0
votes

Sending a post request with proxies but keep running into proxy error.

Already tried multiple solutions on stackoverflow for [WinError 10061] No connection could be made because the target machine actively refused it.

Tried changing, system settings, verified if the remote server is existing and running, also no HTTP_PROXY environment variable is set in the system.

import requests

proxy = {IP_ADDRESS:PORT}  #proxy
proxy = {'https': 'https://' + proxy}

#standard header
header={
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "Referer": "https://tres-bien.com/adidas-yeezy-boost-350-v2-black-fu9006-fw19",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8"
}

#payload to be posted
payload = {
      "form_key":"1UGlG3F69LytBaMF",
      "sku":"adi-fw19-003",
      # above two values are dynamically populating the field; hardcoded the value here to help you replicate.
      "fullname": "myname",
      "email": "[email protected]",
      "address": "myaddress",
      "zipcode": "areacode",
      "city": "mycity" ,
      "country": "mycountry",
      "phone": "myphonenumber",
      "Size_raffle":"US_11"
}

r = requests.post(url, proxies=proxy, headers=header, verify=False, json=payload)

print(r.status_code)

Expected output: 200, alongside an email verification sent to my email address.

Actual output: requests.exceptions.ProxyError: HTTPSConnectionPool(host='tres-bien.com', port=443): Max retries exceeded with url: /adidas-yeezy-boost-350-v2-black-fu9006-fw19 (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',)))

1

1 Answers

0
votes

Quite a few things are wrong here... (after looking at the raffle page you're trying to post to, I suspect it is https://tres-bien.com/adidas-yeezy-boost-350-v2-black-fu9006-fw19 based on the exception you posted).

1) I'm not sure whats going on with your first definition of proxy as a dict instead of a string. That said, it's probably a good practice to use both http and https proxies. If your proxy can support https then it should be able to support http.

proxy = {
    'http': 'http://{}:{}'.format(IP_ADDRESS, PORT),
    'https': 'https://{}:{}'.format(IP_ADDRESS, PORT)
}

2) Second issue is that the raffle you're trying to submit to takes url encoded form data, not json. Thus your request should be structured like:

r = requests.post(
    url=url, 
    headers=headers,
    data=payload
)

3) That page has a ReCaptcha present, which is missing from your form payload. This isn't why your request is getting a connection error, but you're not going to successfully submit a form that has a ReCaptcha field without a proper token.

4) Finally, I suspect the root of your ProxyError is you are trying to POST to the wrong url. Looking at Chrome Inspector, you should be submitting this data to https://tres-bien.com/tbscatalog/manage/rafflepost/ whereas your exception output indicates you are POSTing to https://tres-bien.com/adidas-yeezy-boost-350-v2-black-fu9006-fw19

Good luck with the shoes.