0

I've been pulling my hair out the past couple of days trying to get a Python http request to work. I can get it working using Postman, but for some reason it just won't work no matter what I do in Python. I'm hoping if I can compare some raw version of the two requests I can see what the differences might be.

For Postman, I'm simply POSTing like this:

enter image description here

The header is an authentication token, identical to the one I'm using in Python. Here's my python code:

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

But I get a 500 response:

[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)

Matt Takao
  • 2,406
  • 3
  • 16
  • 30

1 Answers1

2

I resolved this by changing the parameter in post() to just data=body

Matt Takao
  • 2,406
  • 3
  • 16
  • 30