Python请求聊天系统中的post错误响应

Python请求聊天系统中的post错误响应,python,python-requests,Python,Python Requests,我想通过python在系统上自动聊天和发送照片。但是请告诉我下面的错误。你能告诉我怎么修吗? 我的方法是使用Python请求post()方法 文件请求URL的信息 Request URL: https://11.chat.com/file-api/v2/teams/123/rooms/123/attachment/files Request Method: POST Status Code: 200 Remote Address: 11.111.11.11:11 Referrer Policy

我想通过python在系统上自动聊天和发送照片。但是请告诉我下面的错误。你能告诉我怎么修吗? 我的方法是使用Python请求post()方法

文件请求URL的信息

Request URL: https://11.chat.com/file-api/v2/teams/123/rooms/123/attachment/files
Request Method: POST
Status Code: 200 
Remote Address: 11.111.11.11:11
Referrer Policy: strict-origin-when-cross-origin
access-control-allow-origin: *
access-control-expose-headers: Accept-Ranges,Content-Encoding,Content-Length,Content-Range
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Mon, 11 Apr 2020 1:36:05 GMT
chat-correlationid: 123-a0c0-11eb-ba75-bbcbc762f736
server: nginx/1.19.0 (Ubuntu)
vary: Accept-Encoding
x-powered-by: Express
:authority: 11.chat.com
:method: POST
:path: /file-api/v2/teams/123/rooms/123/attachment/files
:scheme: https
accept: application/vnd.tosslab.chat-v2+json
accept-encoding: gzip, deflate, br
accept-language: ja,en-US;q=0.9,en;q=0.8,es;q=0.7
authorization: bearer c12a8c2c975a23f73141320f6ad0fab108a6c03e1620fcb71772e5212b1aab745e32791d1b50bc2cb9ae6197e4f1d012
content-length: 103
content-type: application/json;charset=UTF-8
origin: https://www.chat.com
referer: https://www.chat.com/
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
x-account-id: 121c7942-b51d-4fba-932a-74f3df74b215
x-member-id: 1234
x-team-id: 1234
{fileName: "16188033640933e8796c2644e41653c1d0a6286c79c7c", title: "screenshot.jpeg"}
fileName: "16188033640933e8796c2644e41653c1d0a6286c79c7c"
title: "screenshot.jpeg"
Request URL: https://11.chat.com/message-api/v1/teams/1234/rooms/1234/posts
Request Method: POST
Status Code: 200 
Remote Address: 11.111.11.11:111
Referrer Policy: strict-origin-when-cross-origin
access-control-allow-origin: *
access-control-expose-headers: Accept-Ranges,Content-Encoding,Content-Length,Content-Range
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Mon, 11 Apr 2020 01:36:07 GMT
chat-correlationid: 600509c0-a0c0-11eb-8717-a38bfaeb5981
server: nginx/1.14.0 (Ubuntu)
vary: Accept-Encoding
x-powered-by: Express
:authority: 11.chat.com
:method: POST
:path: /message-api/v1/teams/1234/rooms/1234/posts
:scheme: https
accept: application/vnd.tosslab.chat-v2+json
accept-encoding: gzip, deflate, br
accept-language: ja,en-US;q=0.9,en;q=0.8,es;q=0.7
authorization: bearer c122a8c2c975a23f73141320f6ad0fab108a6c03e1620fcb71772e520b1aab745e32791d1b50bc2cb9a1237e4f1d07f6
content-length: 56
content-type: application/json;charset=UTF-8
origin: https://www.chat.com
referer: https://www.chat.com/
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
x-account-id: 121c7942-b51d-4fba-932a-74f3df74b215
x-member-id: 1234
x-team-id: 1234
{title: "TEST", content: "test", fileIds: [1234]}
content: "test"
fileIds: [1234]
title: "TEST"
请求后URL的信息

Request URL: https://11.chat.com/file-api/v2/teams/123/rooms/123/attachment/files
Request Method: POST
Status Code: 200 
Remote Address: 11.111.11.11:11
Referrer Policy: strict-origin-when-cross-origin
access-control-allow-origin: *
access-control-expose-headers: Accept-Ranges,Content-Encoding,Content-Length,Content-Range
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Mon, 11 Apr 2020 1:36:05 GMT
chat-correlationid: 123-a0c0-11eb-ba75-bbcbc762f736
server: nginx/1.19.0 (Ubuntu)
vary: Accept-Encoding
x-powered-by: Express
:authority: 11.chat.com
:method: POST
:path: /file-api/v2/teams/123/rooms/123/attachment/files
:scheme: https
accept: application/vnd.tosslab.chat-v2+json
accept-encoding: gzip, deflate, br
accept-language: ja,en-US;q=0.9,en;q=0.8,es;q=0.7
authorization: bearer c12a8c2c975a23f73141320f6ad0fab108a6c03e1620fcb71772e5212b1aab745e32791d1b50bc2cb9ae6197e4f1d012
content-length: 103
content-type: application/json;charset=UTF-8
origin: https://www.chat.com
referer: https://www.chat.com/
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
x-account-id: 121c7942-b51d-4fba-932a-74f3df74b215
x-member-id: 1234
x-team-id: 1234
{fileName: "16188033640933e8796c2644e41653c1d0a6286c79c7c", title: "screenshot.jpeg"}
fileName: "16188033640933e8796c2644e41653c1d0a6286c79c7c"
title: "screenshot.jpeg"
Request URL: https://11.chat.com/message-api/v1/teams/1234/rooms/1234/posts
Request Method: POST
Status Code: 200 
Remote Address: 11.111.11.11:111
Referrer Policy: strict-origin-when-cross-origin
access-control-allow-origin: *
access-control-expose-headers: Accept-Ranges,Content-Encoding,Content-Length,Content-Range
content-encoding: gzip
content-type: application/json; charset=utf-8
date: Mon, 11 Apr 2020 01:36:07 GMT
chat-correlationid: 600509c0-a0c0-11eb-8717-a38bfaeb5981
server: nginx/1.14.0 (Ubuntu)
vary: Accept-Encoding
x-powered-by: Express
:authority: 11.chat.com
:method: POST
:path: /message-api/v1/teams/1234/rooms/1234/posts
:scheme: https
accept: application/vnd.tosslab.chat-v2+json
accept-encoding: gzip, deflate, br
accept-language: ja,en-US;q=0.9,en;q=0.8,es;q=0.7
authorization: bearer c122a8c2c975a23f73141320f6ad0fab108a6c03e1620fcb71772e520b1aab745e32791d1b50bc2cb9a1237e4f1d07f6
content-length: 56
content-type: application/json;charset=UTF-8
origin: https://www.chat.com
referer: https://www.chat.com/
sec-ch-ua: "Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-site
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
x-account-id: 121c7942-b51d-4fba-932a-74f3df74b215
x-member-id: 1234
x-team-id: 1234
{title: "TEST", content: "test", fileIds: [1234]}
content: "test"
fileIds: [1234]
title: "TEST"
文件请求响应信息

{"id":111,"fromEntity":1234,"teamId":1234,"info":{"inviteUsers":[],"createInfo":{"members":[],"pg_members":[],"ch_members":[]}},"pollId":null,"feedbackType":null,"feedbackId":-1,"status":"created","messageId":1483745833,"time":1618803367054,"toEntity":[17274139],"message":{"id":1483745833,"teamId":13481330,"writerId":13489639,"contentType":"post","permission":740,"updatedAt":"2021-04-19T03:36:07.049Z","createdAt":"2021-04-19T03:36:07.049Z","isThreaded":false,"isEdited":false,"sharedMessages":[],"attachments":[{"content":{"connectInfo":[],"extraInfo":{"thumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c","smallThumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c?size=80","mediumThumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c?size=320","largeThumbnailUrl":"https://chat-box.com/files-thumb/13481330/16188033640933e8796c2644e41653c1d0a6286c79c7c?size=640","width":985,"height":589},"todo":{},"drive":{},"filterType":"image","externalShared":false,"externalUrl":null,"externalCode":null,"fileUrl":"https://files.chat.com/files-private/1234/16188033640933e8796c2644e41653c1d0a6286c79c7c","serverUrl":"s3","ext":"jpeg","size":235967,"icon":"image","type":"image/jpeg","filename":"16188033640933e8796c2644e41653c1d0a6286c79c7c","name":"screenshot.jpeg","title":"screenshot.jpeg"},"contentType":"file","id":1111}],"mentions":[],"info":{"mention":[]},"likedCount":0,"commentCount":0,"formatKey":null,"isFormatted":false,"todoId":null,"postId":null,"pollId":null,"feedbackId":-1,"shareEntities":[1234],"status":"created","linkPreviewId":null,"content":{"title":"TEST","body":"test","connectInfo":[]},"updateTime":1618803367049,"createTime":1618803367049,"deleterId":null,"from":"web"}}
代码

错误

{'access\'u token':'12396DAE54BE29417882F5C5D728221AA5A0','expires\'in':43200,'refresh\'u token':'123139EC591043F23046F3B4B4134B5DB4F7A44512550B6DE60','token\'type:'bearer','ts':161880507661}
持票人
12396dae54be29417882f5c5d72822121aa5a0
图像/jpeg
503
b“
回溯(最近一次呼叫最后一次):
文件“c:/Users/test/Documents/test/test\u post.py”,第78行,在
return\u file\u data=json.loads(response.content)
文件“C:\Users\test\AppData\Local\Programs\Python38-32\lib\json\\ uu_init\u_.py”,第357行,加载
返回\u默认\u解码器。解码
文件“C:\Users\test\AppData\Local\Programs\Python38-32\lib\json\decoder.py”,第337行,在decode中
obj,end=self.raw\u decode(s,idx=\u w(s,0.end())
文件“C:\Users\test\AppData\Local\Programs\Python38-32\lib\json\decoder.py”,第355行,原始解码
从None引发JSONDecodeError(“预期值”,s,err.value)
json.decoder.JSONDecodeError:预期值:第1行第1列(字符0)
PS C:\Users\test>

如果有人知道,请告诉我。

根据错误日志,您得到的响应似乎是空数据

状态503表示API中可能有错误,因此响应为空

您可以直接使用
resp.json()
方法而不是
json.dump(resp.content)


还要添加对
response.status\u code==200的检查,然后从响应中获取内容。

谢谢你的回答,我按照你告诉我的那样更改了它,但是我从None json.decoder.JSONDecodeError中得到了相同的错误
raise JSONDecodeError(“期望值”,s,err.value)。JSondeCoderror:期望值:第1行第1列(char 0)
response.status\u code==200
如何检查代码是否为200?对不起,如果response.status\u code==200:
则继续下一个逻辑,则此
中没有介绍我。else中止函数
return_file_data = response.json()