Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
如何使用application/x-www-form-urlencoded为原始数据post在python中发出post请求_Python_Python 3.x_Python Requests_Http Headers_Postman - Fatal编程技术网

如何使用application/x-www-form-urlencoded为原始数据post在python中发出post请求

如何使用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

我尝试向服务器发出post请求,并在邮递员中得到回复。它的工作很好。但当我在python中尝试这一点时,服务器会发送“无效客户机”作为回复。这是我的python代码

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)