首页 > 解决方案 > 如何在 python 中使用存储的变量进行发布请求

问题描述

尝试在 python 中发出 post 请求,我收到此错误

import requests

token='Bearer aslkdjndskgns'

endpoint = "https://aap.xyz"

phone_number='9177903753951'

data = {"number":phone_number}

datas = str(data)

headers={"authorization":token}
a=(requests.post(endpoint, data=datas, headers=headers).json())

我收到这个错误

invalid character 'p' looking for beginning of value "

标签: pythonjsonpython-3.xpython-requests

解决方案


请尝试以下代码,看看它是否解决了您的问题。

import requests

token='Bearer aslkdjndskgns'

endpoint = 'https://aap.xyz'
data = {'number':'9177903753951'}
headers={"authorization":token}

a=(requests.post(endpoint, data=data, headers=headers).json())

print(a)


推荐阅读