我试图通过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>
二进制读取将非常有用,因为图像视频以二进制读取模式存储。媒体文件以二进制模式上载。