[英]python 2.7 requests.get() returning cookie raising TypeError
我正在對內部服務器進行簡單的HTTP請求身份驗證,取回cookie,然后命中Cassandra RESTful服務器以獲取數據。 返回cookie時,requests.get()會阻塞。
我有一個curl腳本可以成功提取數據,我寧願使用純python處理響應JSON數據。
以下是我做錯了什么的任何線索? 我丟棄了cookie,它看起來不錯,與我的curl cookie非常相似。
克雷格
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)
請求假設cookies
參數是一個字典,但是您正在authCookie
傳遞字符串對象authCookie
。
當請求嘗試將字符串authCookie
視為字典時,將引發異常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.