如何使用application/x-www-form-urlencoded为原始数据post在python中发出post请求
我尝试向服务器发出post请求,并在邮递员中得到回复。它的工作很好。但当我在python中尝试这一点时,服务器会发送“无效客户机”作为回复。这是我的python代码如何使用application/x-www-form-urlencoded为原始数据post在python中发出post请求,python,python-3.x,python-requests,http-headers,postman,Python,Python 3.x,Python Requests,Http Headers,Postman,我尝试向服务器发出post请求,并在邮递员中得到回复。它的工作很好。但当我在python中尝试这一点时,服务器会发送“无效客户机”作为回复。这是我的python代码 import mysql.connector import requests import json import urllib3 import time urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) mydb = mysql.connec
import mysql.connector
import requests
import json
import urllib3
import time
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
mydb = mysql.connector.connect(
host = "localhost",
user = "root",
password = "",
database = "python-db"
)
mycursor = mydb.cursor()
url = "https://example.com/oauth2/token"
header = {
"Content-Type":"application/x-www-form-urlencoded",
"Content-Length":"121",
"Host":"example.com",
"Connection":"Keep-Alive",
"Accept-Encoding":"gzip",
"User-Agent":"okhttp/3.11.0"
}
payload = {b"scope=scope1&password=123&client_id=789&username=951&grant_type=password"}
response = requests.post(url, data=(payload), headers=header, verify=False)
r_json = response.json()
print(r_json)
我在《邮递员》中尝试了这些标题和数据,效果很好。在postman中,有效负载数据类型为raw。错误是什么?我如何修复此问题?非常感谢您将其放在()括号中
payload ="scope=scope1&password=123&client_id=789&username=951&grant_type=password"
response = requests.post(url, data=payload, headers=header, verify=False)