Python Test API - 001-安装requests库

安装

1.        用pip安装的:pip install requests 

2.        requests一直在Github上被积极开发着,路径在 https://github.com/requests/requests

  

使用requests的简单例子

import requests

r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
print(r.status_code)
print(r.headers['content-type'])
print(r.encoding)
print(r.text)
print(r.json())
C:\Python35\python.exe D:/pyjd/djanRestPro/api/tests.py
403
application/json; charset=utf-8
utf-8
{"message":"Maximum number of login attempts exceeded. Please try again later.","documentation_url":"https://developer.github.com/v3"}
{'documentation_url': 'https://developer.github.com/v3', 'message': 'Maximum number of login attempts exceeded. Please try again later.'}

Requests支持的功能:

  • 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
  • Automatic Content Decoding
  • Unicode Response Bodies
  • Multipart File Uploads
  • HTTP(S) Proxy Support
  • Connection Timeouts
  • Streaming Downloads
  • .netrc Support
  • Chunked Requests

Requests officially supports Python 2.7 & 3.4–3.6,and runs great on PyPy.




猜你喜欢

转载自blog.csdn.net/Pansc2004/article/details/80730860
今日推荐