httpx

Disable ssl verification on a third party module using HTTPX

Disable ssl verification on a third party module using HTTPX Question: I’m using a module that uses httpx to make a request. Because of my company’s network policy, I get a CERTIFICATE_VERIFY_FAILED every time I try to run my code. The data I’m sending and receiving in the request is not sensitive so I want …

Total answers: 1

Handle Request payload using HTTPX for post data and capcha key to google recapchaV2

Handle Request payload using HTTPX for post data and capcha key to google recapchaV2 Question: I’m trying to send the key I got from anti captcha, an example of the key is like this { "errorId":0, "status":"ready", "solution": { "gRecaptchaResponse":"3AHJ_VuvYIBNBW5yyv0zRYJ75VkOKvhKj9_xGBJKnQimF72rfoq3Iy-DyGHMwLAo6a3" }, "cost":"0.001500", "ip":"46.98.54.221", "createTime":1472205564, "endTime":1472205570, "solveCount":"0" } I’m trying to send the value in the …

Total answers: 1

Monkeypatching/mocking the HTTPX external requests

Monkeypatching/mocking the HTTPX external requests Question: I’m trying to monkeypatch the external request. Here is the code of a web endpoint: import httpx, json … @app.get(‘/test’) async def view_test(request): async with httpx.AsyncClient() as client: # sending external request api_response = await client.get( f’https://jsonplaceholder.typicode.com/todos/1′, timeout=10, ) resp = api_response.json() # modifying the result resp[‘foo’] = 0 …

Total answers: 1

Python3.8 asyncio: RuntimeWarning: coroutine was never awaited

Python3.8 asyncio: RuntimeWarning: coroutine was never awaited Question: I am new with async functions and i’m trying to make multiple calls from an external API. concurrent.Futures is not quite enough to retrieve the responses so i tried with asyncio and httpx but the process is throwing an error unknown and difficult to debug for me. …

Total answers: 1

Why does asyncio.create_task and asyncio.ensure_future behave differently when creating httpx tasks for gather?

Why does asyncio.create_task and asyncio.ensure_future behave differently when creating httpx tasks for gather? Question: I found an async httpx example where ensure_future works but create_task doesn’t, but I can’t figure out why. As I’ve understood that create_task is the preferred approach, I’m wondering what’s happening and how I may solve the problem. I’ve been using …

Total answers: 2

Merge dict header to request.headers.raw

Merge dict header to request.headers.raw Question: headers.raw is typing.List[typing.Tuple[bytes, bytes]] I want to merge it into another dict, like the one below: client.build_request(headers=dict(request.headers.raw) | {"foo": "bar"}), However I got the error expected "Union[Headers, Dict[str, str], Dict[bytes, bytes], Sequence[Tuple[str, str]], Sequence[Tuple[bytes, bytes]], None]" Is there some way to do this? I am using Python 3.10, and …

Total answers: 1

get server ip from response of httpx get

get server ip from response of httpx get Question: As the title says, if I do resp=httpx.get(url) how do I get the IP from which the url was resolved? There’s This question about how to do it with requests but the same methods don’t appear to exist in the httpx objects. Asked By: Dean MacGregor …

Total answers: 2

How to replace hyperlinks in StreamingResponse?

How to replace hyperlinks in StreamingResponse? Question: Is that possible to replace hyperlinks in StreamingResponse? I’m using below code to stream HTML content. from starlette.requests import Request from starlette.responses import StreamingResponse from starlette.background import BackgroundTask import httpx client = httpx.AsyncClient(base_url="http://containername:7800/") async def _reverse_proxy(request: Request): url = httpx.URL(path=request.url.path, query=request.url.query.encode("utf-8")) rp_req = client.build_request( request.method, url, headers=request.headers.raw, content=await …

Total answers: 1

Scheduled HTTP Request using FastAPI

Scheduled HTTP Request using FastAPI Question: Inside my FastAPI application, I would like to schedule an HTTP request to be made to check for new results (comparing to database) every X time interval. What would be the easiest way to accomplish this using httpx? Asked By: apod || Source Answers: You can add an async …

Total answers: 1