Hello, I can not install a proxy on http.client

# coding: utf-8 import http.client request = http.client.HTTPConnection('ip-api.com') request.set_tunnel('77.73.65.173', 3128) request.request('GET', '/json') response = request.getresponse() source = response.read() request.close() print(source) 

OSError: Tunnel connection failed: 404 Not Found

Tell me, please, what's the problem?

I use the same proxies via urllib.request, everything works there, but not in http.client ..

  • solved the problem in this way import http.client request = http.client.HTTPConnection('77.73.65.173', 3128) request.set_tunnel('ip-api.com') request.request('GET', '/json') response = request.getresponse() source = response.read() request.close() print(source) - ast
  • @jfs, added a solution to the topic - ast
  • @jfs, Got it. I thank) - ast

1 answer 1

Solved the problem in this way:

 # coding: utf-8 import http.client request = http.client.HTTPConnection('77.73.65.173', 3128) # указываем прокси request.set_tunnel('ip-api.com') # указываем хост, к которому хотим обратиться request.request('GET', '/json') # указываем get response = request.getresponse() source = response.read() request.close() print(source)