• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Communication with python_http_module
 

Communication with python_http_module

on

  • 552 views

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

Statistics

Views

Total Views
552
Views on SlideShare
552
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Communication with python_http_module Communication with python_http_module Presentation Transcript

    • Communication with python HTTP module dreampuf , jul 201212年7月6日星期五
    • introduction urllib2.urlopen("http://www.guokr.com")12年7月6日星期五
    • introduction Pyt hon GC :( urllib2.urlopen("http://www.guokr.com").read()12年7月6日星期五
    • introduction fd = urllib2.urlopen(“http://www.guokr.com”) print fd.read() fd.close()12年7月6日星期五
    • introduction with contextlib.closing(urllib2.urlopen("URL")) as f: print f.read()12年7月6日星期五
    • introduction import contextlib import urllib2 with contextlib.closing(urllib2.urlopen("URL")) as f: print f.read()12年7月6日星期五
    • 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日星期五
    • 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日星期五
    • agenda urllib2 httplib2 pycurl requests12年7月6日星期五
    • Mission Post https://api.github.com/user/repos With some data And our credentials12年7月6日星期五
    • Urllib212年7月6日星期五
    • httplib212年7月6日星期五
    • httplib2 urllib2 - The Missing Manual: HOWTO Fetch Internet Resources with Python www-authenticate: SCHEME realm="REALM"12年7月6日星期五
    • 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日星期五
    • httplib212年7月6日星期五
    • pycurl12年7月6日星期五
    • requests12年7月6日星期五
    • Thank you !12年7月6日星期五
    • 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日星期五