Skip to main content
Question

409 Error When Uploading File via Python

  • May 22, 2025
  • 1 reply
  • 30 views

Forum|alt.badge.img

I am just starting with Box, but after following the API and guides, my Python code will not correctly upload a file to Box. My code is as follows:

from boxsdk import JWTAuth
from boxsdk import Client
import json

# Read in JSON
with open('boxConfig.json') as f:
	data = json.load(f)

#Configure a JWT auth object
sdk = JWTAuth(
	client_id=data["boxAppSettings"]["clientID"],
	client_secret=data["boxAppSettings"]["clientSecret"],
	enterprise_id=data["enterpriseID"],
	jwt_key_id="MyIDHere",
	rsa_private_key_file_sys_path="./private_key.pem",
	rsa_private_key_passphrase="MyPassphraseHere",
)

# Get auth client
client = Client(sdk)


# Set upload values
file_path = './name.txt'
folder_id = '0'

box_file = client.folder(folder_id).upload(file_path)

and the error I get is 

boxsdk.exception.BoxAPIException: 
Message: Item with the same name already exists
Status: 409
Code: item_name_in_use
Request id: s556y9frvi9yxpbb
Headers: {'Content-Length': '465', 'Age': '2', 'Strict-Transport-Security': 'max-age=31536000', 'Vary': 'Accept-Encoding', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache, no-store', 'Date': 'Fri, 01 Jun 2018 03:14:28 GMT', 'Content-Type': 'application/json'}
URL: https://upload.box.com/api/2.0/files/content
Method: POST
Context info: {u'conflicts': {u'sha1': u'072ce64e0c1826f9c7fad494dae918aa41259f0c', u'name': u'name.txt', u'file_version': {u'sha1': u'072ce64e0c1826f9c7fad494dae918aa41259f0c', u'type': u'file_version', u'id': u'***number removed for privacy***306'}, u'sequence_id': u'0', u'etag': u'0', u'type': u'file', u'id': u'29***phone number removed for privacy***'}}

1 reply

Forum|alt.badge.img

Hi ,

 

It looks like the file name you're using is already a currently file that was uploaded. From the code it looks like you're uploading the file to the root folder of your service account. 

 

Can you go to https://app.box.com/master/content, then click on the name of your app in the left nav please? If this is the case you'll see a file named name.txt. If you delete that file and run the code again it should work.

 

- Jon