我遇到以下错误:
ValueError: dictionary update sequence element #0 has length 1; 2 is required
这是我的代码:
SECRET_KEY_HERE被我的密钥替换了。
import requests
url = 'https://app.nanonets.com/api/v2/ImageCategorization/UploadFile/'
data = {'file' :open('C:\\Users\\ch\\Desktop\\1_mONNI1lG9VuiqovpnYqicA.jpg', 'rb'),'category' :('Dog','Hamster','Cat','Rabbit'), 'modelId' :('', '756de8ac-9f09-4fba-87b0-4f30e7e8f12f')}
response = requests.post(url, auth= requests.auth.HTTPBasicAuth('SECRET_KEY_HERE', ''), files=data)
print(response.text)
这是完整的回溯:
Traceback (most recent call last):
File "nano.py", line 6, in <module>
response = requests.post(url, auth= requests.auth.HTTPBasicAuth('', ''), files=data)
File "C:\Python37\lib\site-packages\requests\api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "C:\Python37\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python37\lib\site-packages\requests\sessions.py", line 510, in request
prep = self.prepare_request(req)
File "C:\Python37\lib\site-packages\requests\sessions.py", line 453, in prepare_request
hooks=merge_hooks(request.hooks, self.hooks),
File "C:\Python37\lib\site-packages\requests\models.py", line 316, in prepare
self.prepare_body(data, files, json)
File "C:\Python37\lib\site-packages\requests\models.py", line 504, in prepare_body
(body, content_type) = self._encode_files(files, data)
File "C:\Python37\lib\site-packages\requests\models.py", line 165, in _encode_files
rf = RequestField(name=k, data=fdata, filename=fn, headers=fh)
File "C:\Python37\lib\site-packages\urllib3\fields.py", line 69, in __init__
self.headers = dict(headers)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
这是我第一次使用python,我不确定这里做错了什么,代码是从Nanonets文档页面复制的。
你能指出我正确的方向吗?
亲切的问候, 戴夫