Your SlideShare is downloading. ×
Communication with python_http_module
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Communication with python_http_module

400

Published on

Introduction the python module used for in request of URL is Restful API

Introduction the python module used for in request of URL is Restful API

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
400
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Communication with python HTTP module dreampuf , jul 201212年7月6日星期五
  • 2. introduction urllib2.urlopen("http://www.guokr.com")12年7月6日星期五
  • 3. introduction Pyt hon GC :( urllib2.urlopen("http://www.guokr.com").read()12年7月6日星期五
  • 4. introduction fd = urllib2.urlopen(“http://www.guokr.com”) print fd.read() fd.close()12年7月6日星期五
  • 5. introduction with contextlib.closing(urllib2.urlopen("URL")) as f: print f.read()12年7月6日星期五
  • 6. introduction import contextlib import urllib2 with contextlib.closing(urllib2.urlopen("URL")) as f: print f.read()12年7月6日星期五
  • 7. introduction Pyt hon 2.5 from __futrure__ import with_statement :) import contextlib import urllib2 with contextlib.closing(urllib2.urlopen("URL")) as f: print f.read()12年7月6日星期五
  • 8. introduction cj = cookielib.LWPCookieJar() cookie_support = urllib2.HTTPCookieProcessor(cj) opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler) urllib2.install_opener(opener) Build postdata = urllib.urlencode(postdata) headers = {User-Agent:Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20100101 Firefox/8.0} req = urllib2.Request( url = url, data = postdata, headers = headers ) result = urllib2.urlopen(req) Send text = result.read()12年7月6日星期五
  • 9. agenda urllib2 httplib2 pycurl requests12年7月6日星期五
  • 10. Mission Post https://api.github.com/user/repos With some data And our credentials12年7月6日星期五
  • 11. Urllib212年7月6日星期五
  • 12. httplib212年7月6日星期五
  • 13. httplib2 urllib2 - The Missing Manual: HOWTO Fetch Internet Resources with Python www-authenticate: SCHEME realm="REALM"12年7月6日星期五
  • 14. httplib2 Basic Authentication Process 1.Client -> Server Get  /index.html  HTTP/1.0 Host:www.google.com 2.Server -> Client HTTP/1.0  401  Unauthorised Server:  nginx/1.0.13 WWW-­‐AuthenBcate:  Basic  realm="github.com" Content-­‐Type:  text/html Content-­‐Length:  xxx 3.Client -> Server Get  /index.html  HTTP/1.0 Host:www.google.com AuthorizaBon:  Basic  xxxxxxxxxxxxxxxxxxxxxxxxxxxx12年7月6日星期五
  • 15. httplib212年7月6日星期五
  • 16. pycurl12年7月6日星期五
  • 17. requests12年7月6日星期五
  • 18. Thank you !12年7月6日星期五
  • 19. reference •GitHub Document v3 #create http://developer.github.com/v3/repos/#create •Restful API in Python http://isbullsh.it/2012/06/Rest-api-in-python/ •urllib2 - The Missing Manual http://www.voidspace.org.uk/python/articles/urllib2.shtml#id6 •HTTP使用BASIC认证的原理及实现方法 http://space.itpub.net/23071790/viewspace-70936712年7月6日星期五

×