# Using python to upload file

**URL:** <https://community.hubspot.com/t/using-python-to-upload-file/77894>\
**Category:** APIs & Integrations\
**Tags:** python\
**Created:** [March 23, 2023, 10:10pm UTC](https://community.hubspot.com/t/using-python-to-upload-file/77894 "2023-03-23T22:10:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SPark6](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@SPark6](https://community.hubspot.com/u/SPark6)\
**Post date:** [March 23, 2023, 10:10pm UTC](https://community.hubspot.com/t/using-python-to-upload-file/77894/1 "2023-03-23T22:10:48Z")

</div>

Hi, I have been using the legacy API to upload a static file to a folder in hubspot. As the legacy API & the hapi key is expired, I am now trying to use the new API.

```lia-code-sample
 import requests
 import json
 import os

 current_dir = os.getcwd()
 filename = current_dir + '\\loc.csv'

 file_options = {
 'access': 'PUBLIC_INDEXABLE',
 'ttl': 'P3M',
 "overwrite": True,
 'duplicateValidationStrategy': 'NONE',
 'duplicateValidationScope': 'EXACT_FOLDER'
 }

 f = open(filename, 'rb')

 files_data = {
 'file': (filename, f, 'application/octet-stream'),
 'options': (None, json.dumps(file_options), 'text/strings'),
 'folderPath': (None, '/google_store_locator', 'text/strings')
 }

 url = "https://api.hubapi.com/files/v3/files?after=124152"
 YOUR_ACCESS_TOKEN = "***"
 headers = {'content-type': 'application/json',
 'authorization': 'Bearer %s' % YOUR_ACCESS_TOKEN}
 r = requests.post(url, headers=headers, data=files_data)

```

However, the requests outputted the below error message:

Out[12]: ‘\<html\>\n\<head\>\n\<meta http-equiv=“Content-Type” content=“text/html;charset=utf-8”/\>\n\<title\>Error 415 Unsupported Media Type\</title\>\n\</head\>\n\<body\>\<h2\>HTTP ERROR 415\</h2\>\n\<p\>Reason:\n\<pre\> Unsupported Media Type\</pre\>\</p\>\n\</body\>\n\</html\>\n’

What would be the right way to pass a file to the post job?

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [March 24, 2023, 7:29pm UTC](https://community.hubspot.com/t/using-python-to-upload-file/77894/2 "2023-03-24T19:29:35Z")

</div>

Hi, @SPark6 👋 Thanks for your question. To confirm, is the endpoint you’ve been using? [https://legacydocs.hubspot.com/docs/methods/files/v3/upload\_new\_file](https://legacydocs.hubspot.com/docs/methods/files/v3/upload_new_file)  
If so, the endpoint isn’t depreciated, only use of the HAPI key.

Have you tried using a Private App for Authorization in your header for the endpoint you previously used?

Hey, @ChrisoKlepke @tominal do either one of y’all have an example request you can share with @SPark6?

Best,

Jaycee
