Home  >  Article  >  Backend Development  >  Detailed introduction to network programming

Detailed introduction to network programming

零下一度
零下一度Original
2017-07-24 17:26:091633browse

Python has built-in libraries that encapsulate many common network protocols, so python has become a powerful network programming tool. Here is a brief description of python's network programming.

urllib and urllib2 modules

urllib and urllib2 are the most powerful network working libraries in the Python standard library. Here is a brief introduction to the urllib module. This time we mainly use several commonly used modules in the urllib module:

urlopen
parse
urlencode
quote
unquote
_safe_quoters
unquote_plus

GET request:

Use urllib to make a get request of the http protocol and obtain Return value of the interface:

 urllib.request = res =(res.decode())

POST request:

 urllib.request  urllib.parse = data =: : : param =res ==(type(res_str), res_str)

Note: When using urllib to request the post interface, in the above example, post The request parameter type of the interface is in key-value format, and parameters in json format are not applicable.

Quote module

Escapes special characters when the requested URL contains special characters.

 urllib.parse = new_url =(new_url)

Unquote module

Performs parsing operations on escaped special characters.

 urllib.parse = new_url =(, unquote_plus(url4))

The above is a brief introduction to urllib. When processing the interface, please also refer to the requests module~~~

<br>

The above is the detailed content of Detailed introduction to network programming. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn