蟒蛇 - ValueError错误:需要比1的值更解压 [英] Python - ValueError: need more than 1 value to unpack

查看:106
本文介绍了蟒蛇 - ValueError错误:需要比1的值更解压的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查这个问题的Python的oauth2 - 使申请我与VIMEO整合工作的我Web应用程序。

起初,我得到了一个 oauth_signature ,我没有任何问题(没有错误),我想这些事情再一次从第一,现在我得到的 ValueError错误:需要多个值解压,而提出这个要求。

 >>> R = request.GET中(URL,标题=标题)

您可以在这里 https://gist.github.com/2949182

该错误是

 回溯(最后最近一次调用):
文件<&控制台GT;,1号线,上述<&模块GT;
文件/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/api.py51行,在GET
返回请求(GET,网址,** kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/api.py39行,在请求
返回s.request(方法=方法,URL =网址,** kwargs)
文件/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/sessions.py,线路159,在请求
头[K] = header_expand(v)的
文件/usr/local/lib/python2.7/dist-packages/requests-0.10.1-py2.7.egg/requests/utils.py线152,在header_expand
在历数(头)我,(值,则params):
ValueError错误:需要超过1的数值来解压

谢谢!

更新

 >>>头
{'授权': 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'}


要能够解开字典你将不得不使用.items(),所以code会是这样的:

 对于我,(值,则params)在枚举(headers.items()):

现在因为这是不是你的code和你不能改变它,有什么错误是告诉你的是,标题不应该是一个字典,而是一元组(或清单),如果传递的头像这样的:

 标题= [(授权,值)]

它应该工作。

编辑:这不作品。现在,词典版本{授权:值}。为我工作,也许更新请求帮助

Please check this question Python oauth2 - making request I am working with vimeo integration in my web application.

Initially I got an oauth_signature and I had no problems(no errors), I tried those things once again from the first and Now I'm getting ValueError: need more than 1 value to unpack while making this request

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

You can check out my code here https://gist.github.com/2949182

The error is

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

Thanks!

UPDATE

>>> 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'}

解决方案

to be able to unpack a dictionary you would have to use the .items(), so the code would be like this:

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

now since that is not your code and you can't change it, what the error is telling you is that the headers should not be a dictionary but a tuple (or a list), if you pass the header like this:

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

it should work.

EDIT: This doesn't works. Now the dictionary version {"Authorization": "Values"} works for me, maybe updating requests will help.

这篇关于蟒蛇 - ValueError错误:需要比1的值更解压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆