SystemError: error return without exception set, when using requests and debugger

I had a similar problem when using Gensim Word2vec models, also using debugger in Python 3.6 / PyCharm 2018.2. Just as a quick fix, I found a solution by setting an environment variable: PYDEVD_USE_FRAME_EVAL=NO This can be done easily in PyCharm by settings environment variables in PyCharm run configuration. After setting this variable, I could … Read more

Requests — how to tell if you’re getting a success message?

The response has an ok property. Use that: if response.ok: … The implementation is just a try/except around Response.raise_for_status, which is itself checks the status code. @property def ok(self): “””Returns True if :attr:`status_code` is less than 400, False if not. This attribute checks if the status code of the response is between 400 and 600 … Read more

Python Requests vs PyCurl Performance

I wrote you a full benchmark, using a trivial Flask application backed by gUnicorn/meinheld + nginx (for performance and HTTPS), and seeing how long it takes to complete 10,000 requests. Tests are run in AWS on a pair of unloaded c4.large instances, and the server instance was not CPU-limited. TL;DR summary: if you’re doing a … Read more

Python requests module sends JSON string instead of x-www-form-urlencoded param string

The reason you’re getting JSON is because you’re explicitly calling json.dumps to generate a JSON string. Just don’t do that, and you won’t get a JSON string. In other words, change your first line to this: data = {‘param1’: ‘value1’, ‘param2’: ‘value2’} As the docs explain, if you pass a dict as the data value, … Read more

Fastest parallel requests in Python

Instead of using multithreading or asyncio.executor you should use aiohttp, which is the equivalent of requests but with asynchronous support. import asyncio import aiohttp import time websites = “””https://www.youtube.com https://www.facebook.com https://www.baidu.com https://www.yahoo.com https://www.amazon.com https://www.wikipedia.org http://www.qq.com https://www.google.co.in https://www.twitter.com https://www.live.com http://www.taobao.com https://www.bing.com https://www.instagram.com http://www.weibo.com http://www.sina.com.cn https://www.linkedin.com http://www.yahoo.co.jp http://www.msn.com http://www.uol.com.br https://www.google.de http://www.yandex.ru http://www.hao123.com https://www.google.co.uk https://www.reddit.com https://www.ebay.com https://www.google.fr https://www.t.co … Read more

Python: FastAPI error 422 with POST request when sending JSON data

Straight from the documentation: The function parameters will be recognized as follows: If the parameter is also declared in the path, it will be used as a path parameter. If the parameter is of a singular type (like int, float, str, bool, etc) it will be interpreted as a query parameter. If the parameter is … Read more

Progress Bar while download file over http with Requests

I suggest you try tqdm, it’s very easy to use. Example code for downloading with requests library: from tqdm import tqdm import requests url = “http://www.ovh.net/files/10Mb.dat” #big file test # Streaming, so we can iterate over the response. response = requests.get(url, stream=True) total_size_in_bytes= int(response.headers.get(‘content-length’, 0)) block_size = 1024 #1 Kibibyte progress_bar = tqdm(total=total_size_in_bytes, unit=”iB”, unit_scale=True) … Read more