# Discourse API Uploads

**URL:** <https://meta.discourse.org/t/discourse-api-uploads/134545>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [November 27, 2019, 2:00pm UTC](https://meta.discourse.org/t/discourse-api-uploads/134545 "2019-11-27T14:00:55Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Robert\_Work](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@Robert\_Work](https://meta.discourse.org/u/Robert_Work)\
**Post date:** [November 27, 2019, 2:00pm UTC](https://meta.discourse.org/t/discourse-api-uploads/134545/1 "2019-11-27T14:00:55Z")

</div>

Hello!

I have a question about how I can using Python3 upload a file. I tried to do something like that, but I still get error.

```plaintext
> import requests
headers = {
    'content-type': 'multipart/form-data', #application/x-www-form-urlencoded ??
    'Api-Key': 'MyWorkingKey',
    'Api-Username': 'discourseAdmin',
}
URL = "https://discourse.com/uploads.json"
content = open('FULL_PATH_TO/avatar.jpg', 'rb').read()
data={"type": "avatar",'files[]': ('avatar.jpg', content, 'image/jpeg')}
requests.post(URL, headers=headers, data=data)

*Status Code: 422*
*Response TExt: '{"failed":"FAILED","message":"undefined method `tempfile\' for \\"avatar.jpg\\":String"}'*

```

I did upload the file via this curl:

```
curl -X POST https://discourse.com/uploads.json \
-H "content-type: multipart/form-data;" \
-H "Api-Key: MyWorkingKey" \
-H "Api-Username: discourseAdmin" \
-F "type=avatar" \
-F "files[]=@FULL_PATH_TO/avatar.jpg"

```

Unfortunately, I did not successfully move this curl command into Python.

---

_[View the full topic](https://meta.discourse.org/t/discourse-api-uploads/134545)._
