1. 背景
用Fastapi开发接口,每次用k8s部署后都报307,每次都不长记性,每次都调试了很久,搞得十分抓狂。仅以此文,加深印象。
2. 步骤
2.1 问题
- 代码
@app.post("/xxx/")
def xxx(item: item):
return {"data":"hello world"}
- 调用
import requests
import json
url = "https://ceshi.com/xxx"
headers = {
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
3、报错
2.2 解决方案
巨坑爹,调用方式出现问题!!
url记得跟代码保持一致。
- 调用
import requests
import json
url = "https://ceshi.com/xxx/" ##加上下划线即可。。。。。
headers = {
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
以上,End!