Curl works but not Python requests

前端 未结 3 1671
挽巷
挽巷 2021-02-12 19:59

I am trying to fetch a JSON response from http://erdos.sdslabs.co/users/shagun.json. Using browser/Python\'s Requests library leads to an authentication error, but curl seems t

3条回答
  •  情话喂你
    2021-02-12 20:28

    In case you have a proxy configured at your environment, define it at your session/request as well.

    For example with session:

        my_proxies = {  
            'http': 'http://myproxy:8080',  
            'https': 'https://myproxy:8080'  
        }
    
        session = requests.Session()  
        request = requests.Request('POST', 'http://my.domain.com', data=params_template, headers=req_headers, proxies=my_proxies)  
        prepped = session.prepare_request(request)  
        response = session.send(prepped)  
    

    see documentation:
    request http://docs.python-requests.org/en/master/user/quickstart/
    session http://docs.python-requests.org/en/master/user/advanced/

提交回复
热议问题