NadalVRoMa / PyLibGen

A python script to download books from libgen.io
74 stars 11 forks source link

Traceback when attempting to see more matches when no more exist #2

Closed calebdavenport closed 7 years ago

calebdavenport commented 7 years ago

Behavior that occurs:

After seeing the response, "Sorry, no more matches." I hit enter once more and the program crashed.

Behavior that should occur:

The user should not be able to continue searching after no more matches have been found. This can be done either by giving a different prompt (e.g. " Type # of book to download or q to quit" or the program should quit once no more matches have been found.

Version:

Python - 3.5.4 beautifulsoup4 - 4.4.1 tabulate - 0.7.5

Logs:

$ python3 pylibgen.py python debugging
2 BOOKS FOUND
  #  Author                   Title                                              Publisher      Year  Lang    Ext    Size
---  -----------------------  -------------------------------------------------  -----------  ------  ------  -----  ------
  1  Kristian Rother          Pro Python Best Practices: Debugging, Testing and  Apress         2017  En      epub   2 Mb
  2  Kristian Rother (auth.)  Pro Python Best Practices: Debugging, Testing and  Apress         2017  En      pdf    5 Mb

 Type # of book to download, q to quit or just press Enter to see more matches: 
Sorry, no more matches.

 Type # of book to download, q to quit or just press Enter to see more matches: 
Traceback (most recent call last):
  File "/usr/lib64/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib64/python3.5/http/client.py", line 1107, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib64/python3.5/http/client.py", line 1152, in _send_request
    self.endheaders(body)
  File "/usr/lib64/python3.5/http/client.py", line 1103, in endheaders
    self._send_output(message_body)
  File "/usr/lib64/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib64/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib64/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib64/python3.5/socket.py", line 694, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib64/python3.5/socket.py", line 733, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

raceback (most recent call last):
  File "pylibgen.py", line 150, in <module>
    raw_books = getSearchResults(search_term, page, sel_column)
  File "pylibgen.py", line 15, in getSearchResults
    source = request.urlopen(url)
  File "/usr/lib64/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib64/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib64/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib64/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib64/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>
NadalVRoMa commented 7 years ago

hmm, i'm not able to reproduce the crash. Anyway, I'm going to implement your suggestion since it seems reasonable.