我正在尝试将数据发布到通过URL "http://data.bioontology.org/annotator?text=" + theTextData
获取文本数据的网站中>
我想使用POST URI来获取数据。这是我的代码:
def get_annotations(text, url): headers = [('Authorization', 'apikey token=' + API_KEY)] data = text response = requests.request("POST",url,headers=headers,data=data) return response.text.encode('utf-8') annotations = get_annotations(text, "http://data.bioontology.org/annotator?text=" + urllib.parse.quote(text))
我在运行该错误时收到此错误:
Traceback (most recent call last): ... response = requests.request("POST",url,headers=headers,data=data) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/api.py", line 61, in request return session.request(method=method, url=url, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/sessions.py", line 516, in request prep = self.prepare_request(req) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/sessions.py", line 449, in prepare_request p.prepare( File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 315, in prepare self.prepare_headers(headers) File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/requests/models.py", line 447, in prepare_headers for header in headers.items(): AttributeError: 'list' object has no attribute 'items'
我该如何解决?我是否使用POST错误?
我正在尝试将数据发布到通过URL获取文本数据的网站中:“ http://data.bioontology.org/annotator?text=” + theTextData我想使用POST URI来获取数据。这是我的代码:...
您的标题应该是字典,而不是列表中的元组。