Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Python Requests #29

Merged
merged 1 commit into from
Oct 19, 2015
Merged

Conversation

anoopvalluthadam
Copy link
Contributor

No description provided.

@sylvestre
Copy link
Contributor

Could you reference the issue # ? Thanks
By the way, what is the advantage of Python Requests ?

@anoopvalluthadam
Copy link
Contributor Author

#4

@sylvestre
Copy link
Contributor

I meant in the commit message ;)

@anoopvalluthadam
Copy link
Contributor Author

I will do that pull request again!

If you've used languages other than python, you're probably thinking urllib and urllib2 are easy to use, not much code, and highly capable, that's how I used to think. But the Requests package is so unbelievably useful and short that everyone should be using it.

First, it supports a fully restful API, and is as easy as:

import requests
...

resp = requests.get('http://www.mywebsite.com/user')
resp = requests.post('http://www.mywebsite.com/user')
resp = requests.put('http://www.mywebsite.com/user/put')
resp = requests.delete('http://www.mywebsite.com/user/delete')
Regardless of whether GET/POST you never have to encode parameters again, it simply takes a dictionary as an argument and is good to go.

userdata = {"firstname": "John", "lastname": "Doe", "password": "jdoe123"}
resp = requests.post('http://www.mywebsite.com/user', params=userdata)
Plus it even has a built in json decoder (again, i know json.loads() isn't a lot more to write, but this sure is convenient):

resp.json()
Or if your response data is just text, use:

resp.text
This is just the tip of the iceberg. This is the list of features from the requests site:

International Domains and URLs
Keep-Alive & Connection Pooling
Sessions with Cookie Persistence
Browser-style SSL Verification
Basic/Digest Authentication
Elegant Key/Value Cookies
Automatic Decompression
Unicode Response Bodies
Multipart File Uploads
Connection Timeouts
.netrc support
List item
Python 2.6—3.4
Thread-safe.

@sylvestre
Copy link
Contributor

Le 19/10/2015 14:55, Anoop Valluthadam a écrit :

I will do that pull request again!

just do
git commit --amend
git push -f

and that is it :)

Thanks for the information

sylvestre added a commit that referenced this pull request Oct 19, 2015
@sylvestre sylvestre merged commit faafc81 into mozilla:master Oct 19, 2015
@sylvestre sylvestre mentioned this pull request Oct 19, 2015
@anoopvalluthadam anoopvalluthadam deleted the issue_4 branch October 26, 2015 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants