Home > other >  Python HackerNews API connection issue
Python HackerNews API connection issue

Time:10-02

Now learn Python Crash Course of this part of the API, I according to the teaching material of Hacker News API code input
The import requests

From the operator import itemgetter

# Make an API call, and store the response.
Url='https://hacker-news.firebaseio.com/v0/topstories.json'
R=requests. Get (url)
Print (" Status code: ", r.s tatus_code)

# Process information about each submission.
Submission_ids=r.j son ()
Submission_dicts=[]
For submission_id submission_ids in [30] :
# Make a separate API call for each submission.
Url=(' https://hacker-news.firebaseio.com/v0/item/'+
STR (submission_id) + 'json')
Submission_r=requests. Get (url)
Print (submission_r. Status_code)
Response_dict=submission_r. Json ()

Submission_dict={
'title' : response_dict [' title '],
'link' : 'http://news.ycombinator.com/item? Id="+ STR (submission_id),
'comments' : response_dict. Get (' descendants', 0)
}
Submission_dicts. Append (submission_dict)

Submission_dicts=sorted (submission_dicts, key=itemgetter (' comments'),
Reverse=True)

For submission_dict submission_dicts in:
Print (" \ nTitle: "submission_dict [' title '])
Print (" the Discussion link: "submission_dict [' link '])
Print (" Comments: ", submission_dict [' Comments'])

, but the system did not give the right feedback, give the feedback of the following

Traceback (the most recent call last) :
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ connection py", line 171, in _new_conn
(self. _dns_host, the self. The port), the self. The timeout, * * extra_kw)
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ util \ connection py", line 79, in create_connection
Raise err
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ util \ connection py", line 69, in create_connection
The sock. Connect (sa)
[10060] WinError TimeoutError: 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

During handling of the above exception, another exception occurred:

Traceback (the most recent call last) :
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ connectionpool py", line 600, in urlopen
Chunked=chunked)
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ connectionpool py", line 343, in _make_request
Self. _validate_conn (conn)
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ connectionpool py", line 849, in _validate_conn
Conn. The connect ()
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ connection py", line 314, in the connect
Conn=self. _new_conn ()
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ connection py", line 180, in _new_conn
The self, "Failed to establish a new connection: % s" % e)
Urllib3. Exceptions. NewConnectionError: & lt; Urllib3. Connection. VerifiedHTTPSConnection object at 0 x000002257bbca978 & gt; Failed to establish a new connection: [10060] WinError 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

During handling of the above exception, another exception occurred:

Traceback (the most recent call last) :
File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ requests \ adapters py", line 445, in the send
Timeout=timeout
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ connectionpool py", line 638, in urlopen
_stacktrace=sys. Exc_info () [2])
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages \ urllib3 \ util \ retry py", line 398, the increment in
Raise MaxRetryError (_pool, url, the error or ResponseError (cause))
Urllib3. Exceptions. MaxRetryError: HTTPSConnectionPool (host='hacker-news.firebaseio.com', the port=443) : Max retries exceeded with url:/where v0/topstories. Json (under Caused by NewConnectionError (' & lt; Urllib3. Connection. VerifiedHTTPSConnection object at 0 x000002257bbca978 & gt; Failed to establish a new connection: [10060] WinError 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, '))

During handling of the above exception, another exception occurred:

Traceback (the most recent call last) :
The File "hn_submissions. Py", line 7, in & lt; module>
R=requests. Get (url)
The File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages/requests/API. Py", line 72, in the get
Return the request (' get 'url, params=params, * * kwargs)
File "C: \ Users \ Laeva \ AppData \ \ Roaming \ Python Python36 \ site - packages/requests/API. Py", 58, the line in the request
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related