Home > Software design >  How can i use Session mount to make site calls
How can i use Session mount to make site calls

Time:01-18

I need to make multiple calls by using threading but when mounting the session is giving me a bad request error over http protocol


    gateway = ApiGateway("https://my.com/plp_search_v2",   access_key_id=aws_access_key_id, access_key_secret=aws_secret_access_id, regions=EXTRA_REGIONS)

    

    url = "https://my.com/plp_search_v2"
    header={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) \
    AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'}
    params = {
                "key": "9f36aeafbe60771e321a7cc95a78140772ab3e96",
                "category": "ziogr",
                "channel": "WEB",
                "count": "24",
            }
    session = requests.Session()
    session.mount("https://", gateway)
    session.mount("http://", gateway)
    response = session.get(url, params=params, headers=header)

I am trying to use the API Gateway from AWS to make calls to that URI and i don't know why without the sessions.mount lines it is working.

The service is always retrieving a 400 bad request and we need to make multiple calls with aws proxy to retrieve some information.

There is a way we can improve this calls to achieve a more proficient result by calling API each time

CodePudding user response:

I used url parse lib to delete the path from the url and after that re do the gateway mount into the session

It is like this

url = "https://redsky.target.com/redsky_aggregations/v1/web/plp_search_v2"
src_parsed = urlparse(url)
src_nopath = "%s://%s" % (src_parsed.scheme, src_parsed.netloc)
session = requests.Session()
session.mount(src_nopath, gateway)
response = session.get(url, stream=True, params=params, headers=header)
  • Related