Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Request doesnt work?
#1
I'm new here and to python so any help would be greatly appreciated.



import requests

response = requests.get("https://www.google.com/", verify=False, timeout=10)

print(response)
Error:
Traceback (most recent call last): File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connection.py", line 204, in _new_conn socket_options=self.socket_options, File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\util\connection.py", line 85, in create_connection raise err File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\util\connection.py", line 73, in create_connection sock.connect(sa) socket.timeout: timed out The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connectionpool.py", line 802, in urlopen **response_kw, File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connectionpool.py", line 491, in _make_request raise new_e File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connectionpool.py", line 467, in _make_request self._validate_conn(conn) File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connectionpool.py", line 1092, in _validate_conn conn.connect() File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connection.py", line 604, in connect self.sock = sock = self._new_conn() File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connection.py", line 212, in _new_conn ) from e urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x00000000032BC088>, 'Connection to www.google.com timed out. (connect timeout=10)') The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\requests\adapters.py", line 497, in send chunked=chunked, File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\connectionpool.py", line 845, in urlopen method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2] File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\urllib3\util\retry.py", line 515, in increment raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type] urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x00000000032BC088>, 'Connection to www.google.com timed out. (connect timeout=10)')) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Marcus\PycharmProjects\pythonProject1\main.py", line 3, in <module> response = requests.get("https://www.google.com/", verify=False, timeout=10) File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\requests\api.py", line 73, in get return request("get", url, params=params, **kwargs) File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\requests\api.py", line 59, in request return session.request(method=method, url=url, **kwargs) File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\requests\sessions.py", line 587, in request resp = self.send(prep, **send_kwargs) File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\requests\sessions.py", line 701, in send r = adapter.send(request, **kwargs) File "C:\Users\Marcus\AppData\Local\Programs\Python\Python37\lib\requests\adapters.py", line 507, in send raise ConnectTimeout(e, request=request) requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x00000000032BC088>, 'Connection to www.google.com timed out. (connect timeout=10)'))
I have all my firewalls off. I have a good connection to google. I am not using a VNP or proxy. I have tried other web sites. I have tried it with no other arguments in then requests function and with every combination I could think of. I have even tried it with headers thinking my ISP is blocking web crawlers (I don't know if they do or not). Im on a Windows 7 and I think I have something configured wrong. If its not that then Im all out of ideas and I dont really know where to start looking if I do.
Reply
#2
why not simply"
>>> import requests
>>> response = requests.get("https://www.google.com/")
>>> if response.status_code == 200:
...     print(response.text)
...
>>>   
response is a dictionary, so need to get results from response.text (or response.content if binary data)

Partial results:
Output:
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="OdPc-1uKS2Cs3a1ijWiZlg">(function(){var _g={kEI:'Tt55ZMfHAp7k5NoPy_K ...
Reply
#3
That is the thing though. I cant get requests.get("https://www.google.com/") to return 200. I cant seem to get request.get to connect to anything at all. I tried your code and got the same error. If I use requests.get in anyway I get that same error.
Reply
#4
Can you reach requests.get("https://www.w3.org/") ?
Reply
#5
(Jun-02-2023, 08:34 PM)Gribouillis Wrote: Can you reach requests.get("https://www.w3.org/") ?

Same thing as before.

Error:
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.w3.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x00000000032B6288>: Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond'))
Reply
#6
There can be problem with your network that block or problem with Requests.
Python 3.7 start to get old now,so you should upgrade
As libraries will soon or already start to drop 3.7.
Eg NumPy which is used a lot as base requirement for many packages in Python.
NumPy Wrote:The Python versions supported in this release are 3.8-3.10, Python 3.7 has been dropped.

Test if network work with other methods eg urllib, curl, or Powsershell.
from urllib.request import urlopen

html = urlopen("https://www.w3.org/")
contents = html.read()
print(contents)
Curl
G:\div_code\hex
λ curl -I "https://www.w3.org/"
HTTP/1.1 200 OK
Date: Sat, 03 Jun 2023 09:46:24 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
content-location: Home.html
last-modified: Sat, 03 Jun 2023 07:20:10 GMT
etag: W/"85d8-5fd347fee3e80-gzip"
Cache-Control: max-age=600
expires: Sat, 03 Jun 2023 09:55:44 GMT
vary: Accept-Encoding
x-backend: www-mirrors
x-request-id: 7d166c551fb44385
strict-transport-security: max-age=15552000; includeSubdomains; preload
content-security-policy: upgrade-insecure-requests
CF-Cache-Status: HIT
Set-Cookie: __cf_bm=NDVxNBDrqY9MceKS3VSaxWpxFsvKbXLhzn5HZ42RhZU-1685785584-0-
AYkvBcoS0wQMIVNZtIWMn+l5XtBCoM27sDfCcoe/oZ8XDKD6wMaOQuQBS9+1MPTTvn3ZuSptWVD2N1Nl3XdAWlU=; path=
/; expires=Sat, 03-Jun-23 10:16:24 GMT; domain=.w3.org; HttpOnly; Secure; SameSite=None
Server: cloudflare
CF-RAY: 7d17023e4d09b4ee-OSL
alt-svc: h3=":443"; ma=86400
PowerShell
PS C:\Windows\System32\WindowsPowerShell\v1.0> $WebResponse = Invoke-WebRequest "https://google.com"
PS C:\Windows\System32\WindowsPowerShell\v1.0> $WebResponse.StatusCode
200
PS C:\Windows\System32\WindowsPowerShell\v1.0> $WebResponse.Content
<!doctype html><html itemscope=""
.....
Reply
#7
Well I thought you was on to something. Deleted everything. I'm now on python 3.8.8, pip 20.2.3 (It does say that is out of date but when I run upgrade it says that is the latest for window 7), and pycharm 2022.3.3.

Same error. Wall
Reply
#8
latest for windows is 3.11.3
Reply
#9
(Jun-04-2023, 09:22 PM)Larz60+ Wrote: latest for windows is 3.11.3

Im on Window 7. I said that on the first post. Tell it to me straight though. Ill go back to Linux before I get another Windows.
Reply
#10
Can you try task that i posted,urllib, curl, or Powsershell.
Then will know if your network is open for other task.

The problem can also be proper certificates installed,
that Windows 7(old) that you use don't have upgrade these.
An other course can be firwall,so if you use any security package try turn of firewall.

Can also try proxy eg free list
import requests

url = "https://www.w3.org/"
proxy = {"http": "209.38.233.119:8080"}
response = requests.get(url, proxies=proxy)
print(response)
print(response.content[:100])
Output:
<Response [200]> b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-str'
These free proxy can go down up down fast,so the one i use(just copy on the first) may not work if you try later,then use new one.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Brick how to work with 2 or more related tables in a Post request ikurorox 0 1,406 Dec-05-2021, 01:01 AM
Last Post: ikurorox

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020