aosabook / 500lines

500 Lines or Less
Other
29.23k stars 5.87k forks source link

Crawler: How to fix the error "ConnectionRefusedError: [Errno 111] Connection refused"? #159

Open loucq123 opened 8 years ago

loucq123 commented 8 years ago

Hi, I'm running the loop-with-callbacks.py in the crawler project. But I always got an error when running a few time of the program.

Traceback (most recent call last):
  File "loop-with-callbacks.py", line 103, in <module>
    callback(event_key, event_mask)
  File "loop-with-callbacks.py", line 40, in connected
    self.sock.send(get.encode('ascii'))
ConnectionRefusedError: [Errno 111] Connection refused

I tried to replace self.sock.send(get.encode('ascii') with self.sock.sendall(get.encode('ascii')), but it got the same error. I can't solve this problem, so I'm looking for some help. And my Python version is 3.4.1, my system is Ubuntu. Best wished!

ajdavis commented 8 years ago

Hi, I just reran this on my system and it works for me:

$ python --version Python 3.4.3 $ python crawler/code/supplemental/loop-with-callbacks.py / /atom.xml /s/b0dcca.css < ... lots of output ... > 1630 URLs fetched in 3.0 seconds, achieved concurrency = 15

I don't think the difference is between Python 3.4.1 versus my 3.4.3. I expect you just can't reach xkcd.com? What happens if you run "curl xkcd.com/"?

On Mon, Oct 12, 2015 at 10:18 AM, Chaoqi Lou notifications@github.com wrote:

Hi, I'm running the loop-with-callbacks.py https://github.com/aosabook/500lines/blob/master/crawler/code/supplemental/loop-with-callbacks.py in the crawler project. But I always got an error when running a few time of the program.

Traceback (most recent call last): File "loop-with-callbacks.py", line 103, in callback(event_key, event_mask) File "loop-with-callbacks.py", line 40, in connected self.sock.send(get.encode('ascii')) ConnectionRefusedError: [Errno 111] Connection refused

I tried to replace self.sock.send(get.encode('ascii') with self.sock.sendall(get.encode('ascii')), but it got the same error. I can't solve this problem, so I'm looking for some help. And my Python version is 3.4.1, my system is Ubuntu. Best wished!

— Reply to this email directly or view it on GitHub https://github.com/aosabook/500lines/issues/159.

asvetlov commented 8 years ago

It should not depend on Python 3.4.1 vs 3.4.3. Looking on the error it's just ConnectionRefused, which means ''xkcd.com" is not available.

loucq123 commented 8 years ago

I do can connect to xkcd.com. And I ran it just now. This time the error message changed.. It could fetch some pages(not very much, about 100 pages) like this

/
/s/919f27.ico
/556/
/about
/s/b0dcca.css
/atom.xml
/archive
/license.html
/rss.xml
/1/
/1588/
/688/
/162/
/150/
<...lots of outputs>

But this time the error message changed..

Traceback (most recent call last):
  File "loop-with-callbacks.py", line 103, in <module>
    callback(event_key, event_mask)
  File "loop-with-callbacks.py", line 46, in read_response
    chunk = self.sock.recv(4096)  # 4k chunk size.
ConnectionResetError: [Errno 104] Connection reset by peer

I google this error, someboby says it is the issue of the server. This really puzzles me. Oh, let me try to use Python 3.4.3 ------------------------------update----------------------------------- I tried use Python 3.4.3, I got the same error above.