1

请检查这个问题Python oauth2 - making request我正在我的 Web 应用程序中使用 vimeo 集成。

最初我得到了一个oauth_signature并且没有任何问题(没有错误),我从一开始就再次尝试了这些事情,现在我得到了ValueError: need more than 1 value to unpack while making this request

>>> r = request.get(url, headers=headers)

你可以在这里查看我的代码https://gist.github.com/2949182

错误是

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/api.py", line 51, in get
return request('get', url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/api.py", line 39, in request
return s.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/sessions.py", line 159, in request
headers[k] = header_expand(v)
File "/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/utils.py", line 152, in header_expand
for i, (value, params) in enumerate(headers):
ValueError: need more than 1 value to unpack

谢谢!

更新

>>> headers
{'Authorization': u'oauth_body_hash=XXXXXXXXXXXXXXXXXXXXXXXXXX,oauth_nonce=3454768,oauth_timestamp=1340035585,oauth_consumer_key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,oauth_signature_method=HMAC-SHA1,oauth_version=1.0,oauth_signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX,oauth_callback=http://127.0.0.1:8000/information/vimeo'}
4

1 回答 1

7

为了能够解压字典,你必须使用 .items(),所以代码是这样的:

for i, (value, params) in enumerate(headers.items()):

现在因为那不是你的代码,你不能改变它,错误告诉你的是,如果你像这样传递标题,标题不应该是字典,而是元组(或列表):

headers = [("Authorization", "Values")]

它应该工作。

编辑:这不起作用。现在字典版本 {"Authorization": "Values"} 对我有用,也许更新请求会有所帮助。

于 2012-06-18T17:01:14.120 回答