我正在对内部服务器执行一个简单的HTTP请求身份验证,获取cookie,然后点击cassandrarestful服务器来获取数据。这个请求.get()退回饼干时噎住了。在
我有一个能成功提取数据的curl脚本,我更愿意用纯python处理响应JSON数据。在
有什么线索可以说明我做错了什么?我把饼干扔了,看起来很好,和我的卷曲饼干很相似。在
克雷格
import requests
import rtim
# this makes the auth and gets the cookie returned, save the cookie
myAuth = requests.get(rtim.rcas_auth_url, auth=(rtim.username, rtim.password),verify=False)
print myAuth.status_code
authCookie=myAuth.headers['set-cookie']
IXhost='xInternalHostName.com:9990'
mylink='http:/%s/v1/BONDISSUE?format=JSONARRAY&issue.isin=%s' % (IXhost, 'US3133XK4V44')
# chokes on next line .... doesn't like the Cookie format
r = requests.get(mylink, cookies=authCookie)
(Pdb) next
TypeError: 'string indices must be integers, not str'
我认为问题出在最后一行:
r = requests.get(mylink, cookies=authCookie)
requests假定
cookies
参数是一个字典,但是您正在向它传递一个字符串对象authCookie
。在当请求试图将字符串
authCookie
视为字典时,将引发异常。在相关问题 更多 >
编程相关推荐