Http request in python

things to do

Preparation

Library installation

console


$ pip install requests

how to use

sample.py


import requests

request_url = 'http://google.com'
request_params = {'param1': 1, 'param2': 2}

request = requests.get(request_url, params=request_params)

if request.status_code == 200:
    print("\n", request.encoding)
    print("\n", request.headers['content-type'])
    print("\n", request.text)

console


 Shift_JIS
 
 text/html; charset=Shift_JIS

 <!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="ja">...</html>

Note

Recommended Posts

Http request in python
Use HTTP cache in Python
Write an HTTP / 2 server in Python
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
A simple HTTP client implemented in Python
Delayed segment tree in Python (debug request)
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Edit fonts in Python
Singleton pattern in Python
Read DXF in python
Daily AtCoder # 53 in Python
Use config.ini in Python
Daily AtCoder # 33 in Python
Solve ABC168D in Python
Logistic distribution in Python