TypeError: expected string or bytes-like object

报错:TypeError: expected string or bytes-like object

代码
import requests

'''
源码分析:
def request(self, method, url,
            params=None, data=None, headers=None, cookies=None, files=None,
            auth=None, timeout=None, allow_redirects=True, proxies=None,
            hooks=None, stream=None, verify=None, cert=None, json=None):
'''

url='http://httpbin.org/get'
headers={
    'User-Agent':'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
    'Cookie':'age=18;name=tom',
}
cookies={
    'age':28,
   
}
r=requests.request(method='get',url=url,headers=headers,cookies=cookies)

print(r.text)

错误原因:

cookies={
    'age':28, 
}
#一律要带引号,所以改成:
cookies={
    'age':'28', 
}

问题解决.

posted @ 2019-09-16 10:41  luowen罗文  阅读(2294)  评论(0编辑  收藏  举报