def test(request):
u="username"
p= 'password'
url='url'
req = urllib2.Request(url)
base64string = base64.encodestring('%s:%s' % (u , p )).replace('\n', '')
d = {}
req.add_data(d) //while authentication i dont send any data, but it is treated as POST request only if data is sent, so sending empty data
req.add_header("Authorization", "Basic %s" % base64string)
req.add_header('Accept', 'application/json')
result = urllib2.urlopen(req)
print result
return HttpResponse(result)
In browser, the response is coming as (bcoz of HttpResponse)
{"token":"abcdef"} //means correct
but the command “print result” is giving something like this :
<addinfourl at 140585554707088 whose fp = <socket._fileobject object at 0x7fdca009e5d0>>
So, i am unable to do any operations on that variable . What i want is only the “token” value from the string . I tried :
type(result) // error
json.dumps(result) //error
json.loads(result) //error
token = result.token //error
you should instead use
resultis the result object.