如何检查邮递员请求和Python http请求之间的差异?

2024-04-20 14:12:45 发布

您现在位置:Python中文网/ 问答频道 /正文

在过去的几天里,我一直在努力让Python的http请求生效。我可以使用Postman让它工作,但由于某些原因,无论我在Python中做什么,它都无法工作。我希望如果我能比较一下这两个请求的原始版本,我就能看出它们的区别。你知道吗

对于邮递员来说,我只是这样发帖:

enter image description here

头是一个身份验证令牌,与我在Python中使用的相同。下面是我的python代码:

text = open(filepath, 'rb').read()
body = aiohttp.formdata.FormData()
body.add_field('files', text, filename=f'{filepath}')
resp = await session.post(url=self.ip_address + '/upload',
                          headers={'Authorization': f'Bearer {self.jwt}'},
                          data={'files': body})
resp.raise_for_status()
html = await resp.text()
return html

但我得到的答复是:

[2019-09-05T18:50:04.751Z] error TypeError: Cannot destructure property refId of 'undefined' or 'null'. at upload (/home/ubuntu/project.strapi/node_modules/strapi-plugin-upload/controllers/Upload.js:26:66) at process._tickCallback (internal/process/next_tick.js:68:7)


Tags: textselfhttphtmljsbodyfilesawait