Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用请求时获得404,但curl工作正常_Python_Python Requests - Fatal编程技术网

Python 使用请求时获得404,但curl工作正常

Python 使用请求时获得404,但curl工作正常,python,python-requests,Python,Python Requests,我使用请求从第三方门户获取一些JSON。 每当我使用请求时,我都会收到一条'{“消息”:“未找到路径”}'错误 但是,使用cURL运行命令效果很好。下面是cURL命令: curlhttps://blah.com/api/v1/nodes --标题“授权:承载人my-long-token-base64” 尝试使用python3/请求执行此操作我有: #convert token to base64 base64_token = base64.b64encode(bytes(access_token

我使用请求从第三方门户获取一些JSON。 每当我使用请求时,我都会收到一条
'{“消息”:“未找到路径”}'
错误 但是,使用cURL运行命令效果很好。下面是cURL命令:

curlhttps://blah.com/api/v1/nodes --标题“授权:承载人my-long-token-base64”

尝试使用python3/请求执行此操作我有:

#convert token to base64
base64_token = base64.b64encode(bytes(access_token, 'utf-8'))
#convert to str
base64_token = base64_token.decode("utf-8")

api = 'https://blah.com/api/v1/nodes'
headers = {'Authorization': 'Bearer ' + base64_token,
'Accept': 'application/json'}
nodes = requests.post(api, headers=headers)
每当我运行此命令时,响应都是
'{“Message”:“未找到路径”}'
我认为这可能与base64令牌有关(这是必需的),但我很确定我已经把这部分做对了,否则我会得到401


有什么想法吗?

这个网站可以帮助你将cURL转换成python-hmm,如果我这样做的话,它就可以工作了:
headers={…:“Authorization':“Bearer mytoken”}
。但是我想把令牌作为变量传入,因为它每30分钟过期一次,我需要获取一个新的令牌