Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Upload file to Box
#1
Hi,

I'm trying to upload a csv file to Box via Mulesoft API, I can upload the file but only the file with last line, I can not upload full file. I m not even getting error.

Please see the following code.
import urllib
import requests

filePath='C:\\Work\\PNC\\Data\\'
fileName= 'CHASE.20171003.csv'
headers = {"Content-type": "application/x-www-form-urlencoded",
           "Accept": "text/plain"}
url = 'https://box-esb.cloudhub.io/uploadCHASEFile'
fileStream = open(filePath+fileName,'rb')

payload = {'Body':fileStream,'Name':fileName}
r=requests.post(url = url, headers=headers, data = payload)
fileStream.close()
print r
Please advice whats wrong in this code.

Thanks
Reply
#2
Question 1: Why are you using python 2.7, latest version is 3.6.3, and 2.7 will only be maintained for a few more years.
try changing:
fileStream = open(filePath+fileName,'rb')
for l in fileStream:
    print l
to:
with open(filePath+fileName,'rb') as filestream:
    for line in fileStream.readlines():
        print(line)
Reply
#3
Thanks Larz60+,

for now we are using 2.7 but may change in future...

Im not printing lines .. just open file and sending to upload.

fileStream = open(filePath+fileName,'rb')
 
payload = {'Body':fileStream,'Name':fileName}
r=requests.post(url = url, headers=headers, data = payload)
fileStream.close()

Please advise
Reply
#4
You were printing in the first post!
review your edits
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 284 Mar-28-2024, 01:46 PM
Last Post: Username_Python1
  '' FTP '' File upload with a specified string and rename midomarc 1 1,178 Apr-17-2023, 03:04 AM
Last Post: bowlofred
  Unable to upload file using FTP korenron 2 2,496 Dec-23-2021, 12:44 PM
Last Post: korenron
  upload Files to FTP and file name is Chinese mollychen 2 2,611 Apr-15-2019, 01:01 AM
Last Post: mollychen
  how to upload a file to my gmail driver after login ?? evilcode1 5 4,190 Nov-06-2018, 07:33 AM
Last Post: evilcode1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020