python 2.7请求.get()返回cookie raining TypeE

2024-04-24 04:15:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在对内部服务器执行一个简单的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'

Tags: the数据import服务器authformatgetcookie
1条回答
网友
1楼 · 发布于 2024-04-24 04:15:54

我认为问题出在最后一行:

r = requests.get(mylink, cookies=authCookie)

requests假定cookies参数是一个字典,但是您正在向它传递一个字符串对象authCookie。在

当请求试图将字符串authCookie视为字典时,将引发异常。在

相关问题 更多 >