.


:




:

































 

 

 

 


. HTTP - , HTTP




  • pickle:
    • PEP 238:
  • JSON json:
    • json JavaScript Object Notation Serializer
    • JSON encoding and ecoding with custom objects in Python

HTTP -

 

HTTP - , HTTP. HTTP GET; , HTTP POST. API HTTP - , , , HTTP PUT HTTP DELETE. , HTTP (GET, POST, PUT DELETE) , , .


HTTP web services are programmatic ways of sending and receiving data from remote servers using nothing but the operations of HTTP. If you want to get data from the server, use HTTP GET; if you want to send new data to the server, use HTTP POST. Some more advanced HTTP web service APIs also allow creating, modifying, and deleting data, using HTTP PUT and HTTP DELETE. In other words, the verbs built into the HTTP protocol (GET, POST, PUT, and DELETE) can map directly to application-level operations for retrieving, creating, modifying, and deleting data.


, . XML JSON , , ( Python, !) HTTP . ; HTTP - ( URL), .


The main advantage of this approach is simplicity, and its simplicity has proven popular. Data usually XML or JSON can be built and stored statically, or generated dynamically by a server-side script, and all major programming languages (including Python, of course!) include an HTTP library for downloading it. Debugging is also easier; because each resource in an HTTP web service has a unique address (in the form of a URL), you can load it in your web browser and immediately see the raw data.


HTTP -:

* Google Data APIs Google, Blogger YouTube.* Flickr Services Flickr.* Twitter API Twitter.*


Examples of HTTP web services:

* Google Data APIs allow you to interact with a wide variety of Google services, including Blogger and YouTube. * Flickr Services allow you to upload and download photos from Flickr. * Twitter API allows you to publish status updates on Twitter. * and many more


Python3 HTTP -: http.client , RFC 2616 HTTP. urllib.request , http.client. API HTTP FTP , HTTP () HTTP .


Python 3 comes with two different libraries for interacting with HTTP web services: http.client is a low-level library that implements RFC 2616, the HTTP protocol. urllib.request is an abstraction layer built on top of http.client. It provides a standard API for accessing both HTTP and FTP servers, automatically follows HTTP redirects, and handles some common forms of HTTP authentication.


, ? . httplib2 . http.client HTTP urllib.request .


So which one should you use? Neither of them. Instead, you should use httplib2, an open source third-party library that implements HTTP more fully than http.client but provides a better abstraction than urllib.request.


, httplib2, HTTP.


To understand why httplib2 is the right choice, you first need to understand HTTP.

 

HTTP

14.2 Features of HTTP


, HTTP .


There are five important features which all HTTP clients should support.

 

14.2.1 Caching


- , . ( ). , , , . , ( ) , . , , , .


The most important thing to understand about any type of web service is that network access is incredibly expensive. I dont mean dollars and cents expensive (although bandwidth aint free). I mean that it takes an extraordinary long time to open a connection, send a request, and retrieve a response from a remote server. Even on the fastest broadband connection, latency (the time it takes to send a request and start retrieving data in a response) can still be higher than you anticipated. A router misbehaves, a packet is dropped, an intermediate proxy is under attack theres never a dull moment on the public internet, and there may be nothing you can do about it.


HTTP . (. . ), . - , . , HTTP.


HTTP is designed with caching in mind. There is an entire class of devices (called caching proxies) whose only job is to sit between you and the rest of the world and minimize network access. Your company or ISP almost certainly maintains caching proxies, even if youre unaware of them. They work because caching built into the HTTP protocol.


. diveintomark.org. wearehugh.com/m.jpg. , HTTP :


Heres a concrete example of how caching works. You visit diveintomark.org in your browser. That page includes a background image, wearehugh.com/m.jpg. When your browser downloads that image, the server includes the following HTTP headers:

HTTP/1.1 200 OKDate: Sun, 31 May 2009 17:14:04 GMTServer: ApacheLast-Modified: Fri, 22 Aug 2008 04:28:16 GMTETag: "3075-ddc8d800"Accept-Ranges: bytesContent-Length: 12405Cache-Control: max-age=31536000, publicExpires: Mon, 31 May 2010 17:14:04 GMTConnection: closeContent-Type: image/jpeg




:


: 2016-11-18; !; : 404 |


:

:

.
==> ...

1634 - | 1607 -


© 2015-2024 lektsii.org - -

: 0.012 .