【发布时间】:2014-05-27 09:37:06
【问题描述】:
当我从http://twistedmatrix.com/documents/13.2.0/web/howto/client.html#auto4 运行代码时,出现<HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD> 错误,
但我不知道如何在请求中添加身份验证。
更新
我将我的代码更新为:
from base64 import b64encode
authorization = b64encode(b"admin:admin")
d = agent.request(
'GET',
'http://172.19.1.76/',
Headers(
{
'User-Agent': ['Twisted Web Client Example'],
b"authorization": b"Basic " + authorization
}
),
None)
但出现以下错误,但我不知道我应该提供列表中的哪些内容。
packages/twisted/web/http_headers.py", line 199, in setRawHeaders
"instance of %r instead" % (name, type(values)))
TypeError: Header entry 'authorization' should be list but found instance of <type 'str'> instead
更新
请求的内容应该在一个列表中,像这样:
"authorization": ["Basic " + authorization]
【问题讨论】:
-
仔细阅读错误信息:)
标签: python twisted twisted.web twisted.client