Questions tagged [httpx]

HTTPX is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2.

HTTPX is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2. For more details, please check the HTTPX website.

162 questions
1
vote
1 answer

How I mock `httpx.connectError` using httpx-pytest package?

I want to mock ConnectionError for my API. I'm creating a python package for one software which if running on localhost:8080 then it will give result correctly. But if the software is not running, then I want to catch it. I'm able to write function…
krishna lodha
  • 381
  • 3
  • 9
1
vote
0 answers

Python httpx post json data with dropdown menu

I'm trying to make a post request to a site with json dropdown data. This is the Payload: {token: "something",…} events: [{type: "impression_user_verify_phone",…}] 0: {type: "impression_user_verify_phone",…} properties:…
Kervn
  • 11
  • 2
1
vote
2 answers

how to persist sessions in httpx python

We can easily create a persistent session using: s = requests.Session() But how to achieve this using httpx library? async with httpx.AsyncClient() as client: response = await client.get( URL, params=params, …
1
vote
0 answers

Multiple client request using httpx Runtime Error: Cannot send a request, as the client has been closed

I have the below piece of code async def get_data(uuid): async with sema, httpx.AsyncClient( base_url=udi_data_url, params=params ) as udi_client: udi_result = udi_client.get(f"/{uuid}") async with sema,…
jhon.smith
  • 1,963
  • 6
  • 30
  • 56
1
vote
0 answers

How to setup a Bearer Token Authentication in AsyncOAuth2Client with authlib

I'm calling an API that has a bearer token authentication. With regular requests package I have successfully implemented it, but then I had to upgrade the class to run concurrent requests. I found authlib.integrations.httpx_client.AsyncOAuth2Client…
Diego-MX
  • 2,279
  • 2
  • 20
  • 35
1
vote
0 answers

httpx python request to webpage wont redirect

Currently making a request to a webpage which redirects a user to another URL (after a few seconds) but my httpx request doesn't follow this redirect, it just stops after it has made the request to the original URL. I am using the follow redirects…
jaal kamza
  • 213
  • 4
  • 12
1
vote
1 answer

How to get httpx.gather() with return_exceptions=True to complete the Queue of tasks when the exception count exceeds the worker count?

I'm using asyncio in concert with the httpx.AsyncClient for the first time and trying to figure out how to complete my list of tasks when some number of them may fail. I'm using a pattern I found in a few places where I populate an asyncio Queue…
Breaks Software
  • 1,721
  • 1
  • 10
  • 15
1
vote
0 answers

How to prevent python httpx from percent encoding my URLs?

I want to send an unencoded query string, with curly braces. Internally httpx is wrapping the passed url in a httpx.URL object and percent encodes the curly braces and I need to send them unencoded. I tried passing the query string as the params…
Ralph Ritoch
  • 3,260
  • 27
  • 37
1
vote
2 answers

Can we use Flask test_client() inside async function

I'm trying to test Flask REST-API end points with pytest using test_client(). But I'm getting an Error saying > RuntimeError: You cannot use AsyncToSync in the same thread as an async event loop - just await the async function directly. Can Anyone…
1
vote
0 answers

aiohttp - Error: 400, message='invalid character in header'

I've started working with AioHttp to use async code in requests. However, I've found that I encounter many pages that don't return a response. Instead I get: Error: 400, message='invalid character in header' I've looked online for a way past this…
cakelover
  • 166
  • 1
  • 8
1
vote
1 answer

Auth Issue using httpx

Valid Response: import requests with requests.Session() as req: req.auth = authdata req.headers.update({ 'x-amz-access-token': access }) r = req.get( 'https://sellingpartnerapi-na.amazon.com/orders/v0/orders/',…
1
vote
0 answers

How to seperate async requests from the underlying socket request

I'm calling the following JSON-EndPoint in order to retrieve the following value of reference_number. Using a normal for loop for 3 requests, I've been able to receive a new token per each request as below: import httpx for _ in range(3): r =…
1
vote
1 answer

How do I make async HTTP requests using httpx (VS requests) in Python?

I'm new to httpx and async and I'm having trouble converting a function that calls to an external API using requests into an asynchronous function using httpx. This is the original function: import requests def get_api_data(url: str) ->…
globus1988
  • 65
  • 7
1
vote
2 answers

Fetching requests in queue concurrently

I have written code that allows me to start fetching the next chunk of data from an API while the previous chunk of data is being processed. I'd like this to be always fetching up to 5 chunks concurrently at any given moment, but the returned data…
demux
  • 4,544
  • 2
  • 32
  • 56
1
vote
1 answer

httpx: How to access specific responses from gathered request tasks?

I want to use HTTPX (within FastAPI, if that matters) to make asynchronous http requests to an outside API and store the responses as individual variables for processing in slightly different ways depending on which URL was fetched. I'm modifying…
noob
  • 328
  • 2
  • 13