2 Replies - 1402 Views - Last Post: 13 November 2012 - 02:21 AM Rate Topic: -----

#1 willbowles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 12

File upload script using requests library

Posted 08 November 2012 - 01:21 AM

Hi all,

I am trying to write a Python script to test my iOS app's API server is running and functioning correctly. I have connected and authenticated with the server fine by logging in using the website credentials. The problem I am having is passing the 'uploaddata' payload into the 'r = requests.post' and getting it to successfully upload the file. The script doesn't return any errors through Terminal but doesn't upload the file.

Any help would be greatly appreciated.

Thanks

Will

import json
import requests

url = 'www.yoururl.com/login.php'
payload = {'email': 'email', 'password': 'password', 'submit': 'log in'}

r = requests.post(url, data = payload)

uploadurl = 'www.yoururl.com'
files = open('/Users/Will/Desktop/APITestDoc.doc', 'rb')

uploaddata = {"file": "APITestDoc.doc", "path": "/Users/Will/Desktop/APITestDoc.doc", "name": "APITestDoc.doc", "redirect": "/"}
headers = {'Content-Disposition': 'form-data'}

r = requests.post(url, data = json.dumps(uploaddata))



Is This A Good Question/Topic? 0
  • +

Replies To: File upload script using requests library

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6021
  • View blog
  • Posts: 23,396
  • Joined: 23-August 08

Re: File upload script using requests library

Posted 08 November 2012 - 09:22 AM

Maybe this is what you're actually looking for.
Was This Post Helpful? 0
  • +
  • -

#3 willbowles  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 17-August 12

Re: File upload script using requests library

Posted 13 November 2012 - 02:21 AM

Thanks for the reply. I spent ages going through the documentation initially but still couldn't get it to upload a file...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1