How to install packages offline?

On the system that has access to internet The pip download command lets you download packages without installing them: pip download -r requirements.txt (In previous versions of pip, this was spelled pip install –download -r requirements.txt.) On the system that has no access to internet Then you can use pip install –no-index –find-links /path/to/download/dir/ -r … Read more

How to POST JSON data with Python Requests?

Starting with Requests version 2.4.2, you can use the json= parameter (which takes a dictionary) instead of data= (which takes a string) in the call: >>> import requests >>> r = requests.post(‘http://httpbin.org/post’, json={“key”: “value”}) >>> r.status_code 200 >>> r.json() {‘args’: {}, ‘data’: ‘{“key”: “value”}’, ‘files’: {}, ‘form’: {}, ‘headers’: {‘Accept’: ‘*/*’, ‘Accept-Encoding’: ‘gzip, deflate’, ‘Connection’: … Read more

Download large file in python with requests

With the following streaming code, the Python memory usage is restricted regardless of the size of the downloaded file: def download_file(url): local_filename = url.split(“https://stackoverflow.com/”)[-1] # NOTE the stream=True parameter below with requests.get(url, stream=True) as r: r.raise_for_status() with open(local_filename, ‘wb’) as f: for chunk in r.iter_content(chunk_size=8192): # If you have chunk encoded response uncomment if # … Read more

how can i change from python2 http request code to python3 Requests [closed]

If you take a look at the docs, it’s pretty simple: http://docs.python-requests.org/en/latest/index.html import requests url = r’http://test.com/login_check.php’ parameters = {‘x’ : ‘0’ , ‘y’ : ‘0’, ‘url’:’login.php’, ‘password’:’1234′, ‘id’:’userid’} login_response = requests.get(url, params=parameters) htmlContent = login_response.text