我是 python 的新手,也是“requests”模块的新手,而且 stackoverflow 对我来说很轻松。:) 如果有人能给我一些关于这对我的代码意味着什么的指示,我将不胜感激。
代码:
import requests
url = 'https://somewebsite.com/svc/api/json/loginUser'
headers = {'User-Agent':'Python _dopost() method',
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset':'Shift_JIS,utf-8;q=0.7,*;q=0.7',
'Accept-Encoding':'gzip,deflate',
'Content-Type':'/plain; charset=UTF-8'}
data = {'<soapenv:Envelope><soapenv:Body><loginUser><email>tacoflavoredkisses@yum.com</email><password>password</password><setcookie>1</setcookie><remember>1</remember></loginUser></soapenv:Body></soapenv:Envelope>'}
r = requests.post(url, data=data, headers=headers)
错误:TypeError:'set' 对象不可下标
有一个很长的python错误,这是一个片段,希望足够了。
TypeError Traceback (most recent call last)
/Library/Python/2.7/site-packages/ipython-0.13.1-py2.7.egg/IPython/utils/py3compat.pyc in execfile(fname, *where)
176 else:
177 filename = fname
--> 178 __builtin__.execfile(filename, *where)
21
22 payload = {'<soapenv:Envelope><soapenv:Body><loginUser><email>tacoflavoredkisses@yum.com</email><password>password</password><setcookie>1</setcookie><remember>1</remember></loginUser></soapenv:Body></soapenv:Envelope>'}
---> 23 r = requests.post(url, data=data, headers=headers)
24
25 print r.status_code
/Library/Python/2.7/site-packages/requests-1.1.0-py2.7.egg/requests/api.pyc in post(url, data, **kwargs)
85 """
86
---> 87 return request('post', url, data=data, **kwargs)
/Library/Python/2.7/site-packages/requests-1.1.0-py2.7.egg/requests/api.pyc in request(method, url, **kwargs)
42
43 session = sessions.Session()
---> 44 return session.request(method=method, url=url, **kwargs)
/Library/Python/2.7/site-packages/requests-1.1.0-py2.7.egg/requests/sessions.pyc in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert)
277
278 # Send the request.
--> 279 resp = self.send(prep, stream=stream, timeout=timeout, verify=verify, cert=cert, proxies=proxies)
/Library/Python/2.7/site-packages/requests-1.1.0-py2.7.egg/requests/sessions.pyc in send(self, request, **kwargs)
372 """Send a given PreparedRequest."""
373 adapter = self.get_adapter(url=request.url)
--> 374 r = adapter.send(request, **kwargs)