如何通过eventbrite API将图片包含在事件中

时间:2019-02-26 15:00:24

标签: api eventbrite

我正在尝试通过eventbrite API发布和发布活动,但是这样做时我无法将媒体上传到活动中。 我设法获得了上传令牌,但不知道下一步该怎么做。

def upload_file(filename):
    data = requests.get("https://www.eventbriteapi.com/v3/media/upload/?type=image-event-logo-preserve-quality&token=__token_here__").json()
    post_args = data['upload_data']
    response = requests.post(data['upload_url'],
        data = post_args,
        files = {
            data['file_parameter_name']: open(filename)   ######error in this line###
        }
    )
    return response, data['upload_token']

ta, tokn = upload_file("C:\\Users\\Nitish\\Desktop\\ERCESS_WORKSPACE\\im.jpg")
  

Traceback (most recent call last):
  File "test.py", line 78, in <module>
    ta, tokn = upload_file(r'im.jpg')
  File "test.py", line 55, in upload_file
    data['file_parameter_name']: open(filename)
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 316, in prepare
    self.prepare_body(data, files, json)
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 504, in prepare_body
    (body, content_type) = self._encode_files(files, data)
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\models.py", line 159, in _encode_files
    fdata = fp.read()
  File "C:\Users\Nitish\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 248: character maps to <undefined>

1 个答案:

答案 0 :(得分:0)

二进制读取模式可能会对您有所帮助。 媒体文件以二进制模式上传。