Requests library get method error in python3.6 - python

When I try to use the requests lib get method I get an error:
(using tkinter)
The error comes from this line:
var.set(get('https://api.ipify.org').text)
the error message says :
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.ipify.org', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [Errno 111] Connection refused',))

Related

Stop displaying this error and print instead just "error"

how to stop displaying this error and print instead just "error":
HTTPConnectionPool(host='domain.com', port=80): Max retries exceeded with url: /api
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f21ceed4690>:
Failed to establish a new connection: [Errno -2] Name or service not known',))

IPFS connection : ConnectionError: HTTPConnectionPool(host='localhost', port=5001)

i'm trying to connect my python program to IPFS api to mint some nft.
I started the IPFS daemon on the " /ip4/127.0.0.1/tcp/5001 " but when i try to connect the client i get this error :
ConnectionError: HTTPConnectionPool(host='localhost', port=5001): Max retries exceeded with url: /api/v0/version?stream-channels=true (Caused by NewConnectionError('<ipfshttpclient.requests_wrapper.HTTPConnection object at 0x7fac0ddf97c0>: Failed to establish a new connection: [Errno 111] Connection refused'))
this is my code :
import ipfshttpclient
client = ipfshttpclient.connect()
print(client.version())
it fails on connect() function, i miss something ? what i can do for can start the connection?
Thank you very much for your help.

Python get and post requests fails with Connection and GetAddrinfo

import requests
r = requests.get('http://http2bin.org/get')
I am getting below errors:
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError:
HTTPConnectionPool(host='http2bin.org', port=80): Max retries exceeded
with url: /get (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x031CAB08>: Failed to establish a new connection: [Errno 11004]
getaddrinfo failed'))
What could be the reason? Is it related to Proxy ?
It's a website problem.Try it with another website surely it would work.

How to catch exception MaxRetryError?

I have a list of proxy addresses for which I want to connect the telegrams-bot.
Proxies can be blocked over time or simply not work, this can be seen by the MaxRetryError error.
But I can't catch an error. I have an error in logs.
I want to catch an error and switch to another proxy server.
from telegram.ext import Updater
REQUEST_KWARGS = {
'proxy_url': proxy_url,
'urllib3_proxy_kwargs': {
'retries': 0
}
}
updater = Updater(token=TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS)
queue = updater.start_polling(bootstrap_retries=0)
.....
raise MaxRetryError(_pool, url, error or ResponseError(cause))
telegram.vendor.ptb_urllib3.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot877422445:AAEGBD0D9stJKMF6PvCClChx8MNMGX-vLEY/deleteWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x11572df98>: Failed to establish a new connection: [Errno 61] Connection refused')))
......
telegram.error.NetworkError: urllib3 HTTPError HTTPSConnectionPool(host='api.telegram.org', port=443): Max retries exceeded with url: /bot877422445:AAEGBD0D9stJKMF6PvCClChx8MNMGX-vLEY/deleteWebhook (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<telegram.vendor.ptb_urllib3.urllib3.connection.VerifiedHTTPSConnection object at 0x11572df98>: Failed to establish a new connection: [Errno 61] Connection refused')))
2019-07-26 16:07:38,553 - telegram.ext.dispatcher - CRITICAL - stopping due to exception in another thread
This way ?
try:
updater = Updater(token=TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS)
queue = updater.start_polling(bootstrap_retries=0)
except MaxRetryError:
#doSomething

ConnectionError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url:

I am getting the Connection error while trying to scrap data from website.
Below is the code I am using.
import requests
import bs4
res=requests.get('https://www.google.com/')
type(res)
soup=bs4.BeautifulSoup(res.text,'lxml')
type(soup)
print(type(soup))
print(soup.prettify())
soup1=soup.select('title')
Below is the complete error message.
raise ConnectionError(e, request=request)
ConnectionError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))

Categories