How do I represent the data passed in Curl --data-urlencode in Python Requests?

An API is provided by an overseas crowdsourcing site called CloudFlower, and I'm stuck when I try to use it.

Code in question

Terminal


curl -X POST --data-urlencode "job[title]={some_title}" --data-urlencode "job[instructions]={some_instructions}" https://api.crowdflower.com/v1/jobs.json?key={api_key}

by http://success.crowdflower.com/customer/portal/articles/1553902

Hmm? I know ? Key = {api_key} as a URL query, but what is --data-urlencode?

--data-urlencode data Posts data like any other --data option, except for HTTP URL encoding. (7.18.0 or later) To conform to CGI, the data part starts with name, puts a delimiter, and then continues to specify the content. The format of the data part is as follows: content The content is URL-encoded and then POSTed. Make sure that the content does not contain the characters = or @. It will match one of the formats below! =content The content is URL-encoded and then POSTed. The first character = is not included in the data. name=content The content part is URL-encoded and then POSTed. Note that the name part is already considered URL-encoded. @filename This will make curl load data from the given file (including any newlines), URL-encode that data and pass it on in the POST. The data is read into curl (including line breaks) from the given file, URL-encoded and then POSTed. name@filename The data is read into curl (including line breaks) from the given file, URL-encoded and then POSTed. An equal sign is added to the name part to form the contents of the name = URL-encoded file. Note that the name part is already considered URL-encoded.

Reference site

curl.1 man page

Well, is it an option used when posting data as well as URL parameters? (That is the same as the parameter?) In this case, the pattern of name = content.

... just send it as a parameter normally !!

Solution

curl2requests.py


import requests

def main():
	payload={'key':APIKey,'job[title]':'Awesome','job[instructions]':'Welcome'}
	r = requests.post("https://api.crowdflower.com/v1/jobs.json",params=payload)

if __nama__='__main__':
	main()

did it!!

It is doubtful that patterns other than name = content can be safely used> <

Reference site

curl.1 man page Requests HTTP for humans

Recommended Posts

How do I represent the data passed in Curl --data-urlencode in Python Requests?
I passed the Python data analysis test, so I summarized the points
[Python] How to do PCA in Python
I wrote the queue in Python
I wrote the stack in Python
How to do R chartr () in Python
I saved the scraped data in CSV!
How many types of Python do you have in Windows 10? I had 5 types.
CURL in python
How to use the C library in Python
I want to do Dunnett's test in Python
I tried simulating the "birthday paradox" in Python
I tried the least squares method in Python
How to specify TLS version in python requests
How to get the files in the [Python] folder
The story of reading HSPICE data in Python
I implemented the inverse gamma function in python
I want to display the progress in Python!
How to study Python 3 engineer certification data analysis test by Python beginner (passed in September 2020)
How an "amateur banker" passed the Python 3 Engineer Certification Basic Exam in a week
What I do when imitating embedded go in python
How to retrieve the nth largest value in Python
Have passed the Python Engineer Certification Data Analysis Exam
Receive the form in Python and do various things
How to get the number of digits in Python
How amateurs passed the Python 3 Engineer Certification Basic Exam
How to do hash calculation with salt in Python
How to know the current directory in Python in Blender
Not being aware of the contents of the data in python
Write data to KINTONE using the Python requests module
I want to write in Python! (3) Utilize the mock
Let's use the open data of "Mamebus" in Python
I tried to summarize how to use pandas in python
How to use the model learned in Lobe in Python
I got InsecurePlatformWarning in python, so I installed requests [security]
[Python] How to output the list values in order
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
I want to use the R dataset in python
How much do you know the basics of Python?
I want to do something in Python when I finish
Try scraping the data of COVID-19 in Tokyo with Python
I tried to simulate how the infection spreads with Python
I checked the Python package pre-installed in Google Cloud Dataflow
[python] How to check if the Key exists in the dictionary
I tried the accuracy of three Stirling's approximations in python
How to debug the Python standard library in Visual Studio
How to use the __call__ method in a Python class
I want to do something like sort uniq in Python
Various ways to calculate the similarity between data in python
[Python beginner] How do I develop and execute Python after all?
How to generate exponential pulse time series data in python
[Understand in the shortest time] Python basics for data analysis
I tried "How to get a method decorated in Python"
[Homology] Count the number of holes in data with Python
I tried programming the chi-square test in Python and Java.
How to get the last (last) value in a list in Python
I didn't know how to use the [python] for statement
I tried to implement the mail sending function in Python
[Python] I tried collecting data using the API of wikipedia
Data science companion in python, how to specify elements in pandas
[Introduction to Python] How to get data with the listdir function