Failing to establish connection using requests - python

I'm trying to use requests to get the text off a website, but it is not working and I'm not sure why. Here is my code:
import requests
print(requests.get("https://projecteuler.net/project/resources/p079_keylog.txt").text)
which gives me the following error:
HTTPSConnectionPool(host='projecteuler.net', port=443): Max retries exceeded
with url: /project/resources/p079_keylog.txt (Caused by
NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnectio
n object at 0x000002701CC15128>: Failed to establish a new connection: [Errno
11001] getaddrinfo failed',))
So it seems a connection cannot be made. The website is valid and works. Is there anything simple I'm doing wrong that may be causing this?

You have a little error:
print(requests.get("https://projecteuler.net/project/resources/p079_keylog.txt").text)
.text is out of url string but anyway I've tried it and I have not found any error. It seems that you have exceeded the number of requests.
Result:
319
680
...

Related

pywhatkit.playonyt is not opening any page

I have MacBook and I am trying to use pywhatkit to play YouTube videos based on the user-provided input. but every time I run my code, it won't take me anywhere and after some time, it will give me this error. (p.s. I am using python 3.8)
Exception has occurred: ConnectionError
HTTPSConnectionPool(host='www.youtube.com', port=443): Max retries exceeded with url: /results?q=Despacito (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fcd17139f70>: Failed to establish a new connection: [Errno 60] Operation timed out'))
this is the code:
import pywhatkit as tube
tube.playonyt('Despacito') # for ex despacito is the user input

Problem using Python client library for Plaid

I'm following the tutorial, but I get an error when I use item_public_token_exchange.
itempublic_tokenexchange
exchange_request = ItemPublicTokenExchangeRequest(
public_token=plaid_token
)
exchange_response = CLIENT.item_public_token_exchange(exchange_request)
the error:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='sandbox', port=80): Max retries exceeded with url: /item/public_token/exchange (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10f1493a0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
Not sure what is happening.
It looks like the problem is that you are trying to connect to sandbox instead of sandbox.plaid.com. Make sure you have your host set up as plaid.Environment.Sandbox (or, alternatively, sandbox.plaid.com) and not just sandbox.

Python-Request - Receiving pointer errors when trying to request data of a website

I'm currently using Python 3.7.6, running the code in a Jupyter Notebook and trying to retrieve data of a website by using the library "request" and I'm receiving a Pointer error -
Code:
from bs4 import BeautifulSoup
import requests
source = requests.get('http://bvmf.bmfbovespa.com.br/indices/ResumoCarteiraTeorica.aspx?Indice=IBOV&idioma=pt-br').text
Error:
OSError: [WinError 10014] - The system detected an invalid pointer address in attempting to use a pointer argument in a call
[...]
NewConnectionError: <urllib3.connection.HTTPConnection object at 0x00000179055507C8>: Failed to establish a new connection: [WinError 10014] The system detected an invalid pointer address in attempting to use a pointer argument in a call
[...]
MaxRetryError: HTTPConnectionPool(host='bvmf.bmfbovespa.com.br.x.ecf9251d0725104833087180eb40dc1a5570.9270ee5e.id.opendns.com', port=80): Max retries exceeded with url: /h/bvmf.bmfbovespa.com.br/indices/ResumoCarteiraTeorica.aspx?X-OpenDNS-Session=_ecf9251d0725104833087180eb40dc1a55709270ee5e_JPweB49M_Indice=IBOV&idioma=pt-br (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000179055507C8>: Failed to establish a new connection: [WinError 10014] The system detected an invalid pointer address in attempting to use a pointer argument in a call'))
[...]
ConnectionError: HTTPConnectionPool(host='bvmf.bmfbovespa.com.br.x.ecf9251d0725104833087180eb40dc1a5570.9270ee5e.id.opendns.com', port=80): Max retries exceeded with url: /h/bvmf.bmfbovespa.com.br/indices/ResumoCarteiraTeorica.aspx?X-OpenDNS-Session=_ecf9251d0725104833087180eb40dc1a55709270ee5e_JPweB49M_Indice=IBOV&idioma=pt-br (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000179055507C8>: Failed to establish a new connection: [WinError 10014] The system detected an invalid pointer address in attempting to use a pointer argument in a call'))
Note: When I try to run the exact same code on my personal computer it works, however when I try to run at my job's it doesn't.
It was actually a proxy issue.
After the following change in the code I could access the content of the website -
proxies = {
"http": "http://myproxy:myport"
}
source = requests.get('http://bvmf.bmfbovespa.com.br/indices/ResumoCarteiraTeorica.aspx?Indice=IBOV&idioma=pt-br', proxies=proxies).text
soup = BeautifulSoup(source, 'html.parser')

Making requests through tor, requests.exceptions.ConnectionError Errno 61: Connection Refused

I'm trying to make a simple request to a whatsmyip site while connected to tor but no matter what I try I continue to get this error:
requests.exceptions.ConnectionError: SOCKSHTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /get (Caused by NewConnectionError('<urllib3.contrib.socks.SOCKSHTTPSConnection object at 0x1018a7438>: Failed to establish a new connection: [Errno 61] Connection refused'))
I've looked at a lot of posts on here with similar issues but I can't seem to find a fix that works.
This is the current code but I've tried multiple ways and its the same error every time:
import requests
def main():
proxies = {
'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050'
}
r = requests.get('https://httpbin.org/get', proxies=proxies)
print(r.text)
if __name__ == '__main__':
main()
Well the error says Max retries exceeded with url:, so possibly could be too many requests has been made from the tor exit nodes ip. Attempt to do it with a new Tor identity and see if that works.
If you wanted to you could catch the exception and put it in a loop to attempt every number of seconds, but this may lead to that ip address being refused by the server for longer.

Requests library get method error in python3.6

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',))

Categories