Skip to main content
 首页 » 编程设计

python之在 flask 中发送帖子请求

2025年05月04日15myhome

<分区>

我正在尝试在 Flask 中发送发布请求。

我想发送带有 Content-Type: application/json 设置为 header 的 json 对象。

我正在使用 requests 模块执行此操作,如下所示:

json_fcm_data = {"data":[{'key':app.config['FCM_APP_TOKEN']}], "notification":[{'title':'Wyslalem cos z serwera', 'body':'Me'}], "to":User.query.filter_by(id=2).first().fcm_token} 
json_string = json.dumps(json_fcm_data) 
print json_string 
res = requests.post('https://fcm.googleapis.com/fcm/send', json=json_string) 

但这给了我:

TypeError: request() got an unexpected keyword argument 'json'

关于如何解决这个问题有什么建议吗?