I got <HTML><HEAD><TITLE>401 Unauthorized</TITLE></HEAD>
error, when I run the code from http://twistedmatrix.com/documents/13.2.0/web/howto/client.html#auto4,
but I don't know how to add authentication in the request.
Update
I updated my code to this:
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)
But got the following error, but I don't know what content in a list should I provide it.
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
Update
The content of the request should be in a single list, like this:
"authorization": ["Basic " + authorization]
You can add headers to requests sent using
Agent
(notice line 29 of the example you linked to).For example, to perform basic authentication/authorization, you could try something like this: