Python 发送带有正确信息的post数据时出现问题

Python 发送带有正确信息的post数据时出现问题,python,python-3.x,python-requests,urllib2,urllib,Python,Python 3.x,Python Requests,Urllib2,Urllib,我正在尝试使用以下标题发送帖子数据: User-Agent: MBAM-C Content-Type: application/json Authorization: True Content-Length: 619 Connection: Close 我最初使用了requests库,但是它会自动在请求中添加头,比如Accept Encoding等 我现在尝试在python 3.x上使用urllib,这是我的post数据: { "IsLocationTrue": "True", "LocTyp

我正在尝试使用以下标题发送帖子数据:

User-Agent: MBAM-C
Content-Type: application/json
Authorization: True
Content-Length: 619
Connection: Close
我最初使用了requests库,但是它会自动在请求中添加头,比如
Accept Encoding

我现在尝试在python 3.x上使用urllib,这是我的post数据:

{
"IsLocationTrue": "True",
"LocType": "country"
}
这正是它应该被发送的方式,而不是URL编码。 但是,当我将其设置为数据时,它会给我以下错误:

TypeError: memoryview: a bytes-like object is required, not 'str'
我试着用
”将整件事变成一个字符串,但是,当然,我遇到了一个错误,它不能是字符串

之后,我只是简单地尝试对字符串进行编码,这使得脚本运行,但是当我分析请求时,post数据中没有发送数据

我不知道还能做什么,救命啊

另外,我使用的是Python3.x,正在使用urllib.request库。

尝试发送以下内容:

postdata=b'''{"IsLocationTrue":"True","LocType":"country"}'''

显示您的代码。但是,没有发送post数据,它正确地设置了标题并执行其他操作,但没有发送post数据中的数据,只是为空