0

How do you convert a -F curl command to requests in python. Specifically, how would you convert the code below to python. I know Facebook has an sdk for this - but I'm curious if this can be done using the requests library

curl
-F 'name=my new ca'
-F 'access_token=<ACCESS_TOKEN>'         HTTPS://graph.Facebook.com/<api_version>/act/customaudiences

Converting to Python using requests - I can't figure out where I am making the error:

import requests
url = 'HTTPS://graph.Facebook.com/<api_version>/act/customaudiences'
param: {'name':'my new ca', 'access_token' = '<ACCESS_TOKEN'}
x = requests.post(url, files = param)

1 Answers1

0

You are looking to submit form data using Python's request or requests module. Maybe these would be helpful:

  1. How to send a "multipart/form-data" with requests in python?

  2. http://curl.haxx.se/docs/manpage.html

Otherwise, just search up "POST", "form data", "python request(s)". There are lots of people out there with similar questions.

Community
  • 1
  • 1
Thrynn
  • 199
  • 2
  • 2
  • 11
  • Thanks! Yes everything I have read basically tells me to put the form and the data in the dictionary and pass it through requests using the 'file' attribute. However, this doesn't work and I'm still getting a 400 error. I was wondering if anyone here had more insight. – user3478832 Oct 22 '15 at 00:22
  • Oh, okay. In that case, you should definitely post your code in the question area. Then people can look it over for you and pinpoint what you're doing correct/incorrectly. Every time you update your question, your question will be "bumped" to the top of the questions queue. (: – Thrynn Oct 22 '15 at 00:33
  • I thought I did post it in the question area? Sorry - new user! – user3478832 Oct 22 '15 at 00:43
  • It's okay. I only see the curl code but not your work in python. Please give an upvote if this has been helpful. – Thrynn Oct 22 '15 at 00:47
  • Thanks - updated with code! This has been helpful - but can't upvoted since I am new - need reputation I think – user3478832 Oct 22 '15 at 00:54
  • No problem. Now that you've updated the post, checkout the Related Questions in the lower right area. They should better address your problem. – Thrynn Oct 22 '15 at 03:58