ptwobrussell / Mining-the-Social-Web-2nd-Edition

The official online compendium for Mining the Social Web, 2nd Edition (O'Reilly, 2013)
http://bit.ly/135dHfs
Other
2.9k stars 1.49k forks source link

urlerror in chapter 1 example 2 #103

Closed philrenaud closed 10 years ago

philrenaud commented 10 years ago

Hi! Up and running with example code, created twitter app + generated access tokens, etc. Mac OSX Mavericks, Chrome, Virtualbox 4.3.4, just downloaded the newest version of Vagrant.

Running iPython Notebook in Chapter 1; example 1, I've put in all my credentials (left as --- here) and get the following, which seems correct/as expected from the book:


import twitter

CONSUMER_KEY = '---' CONSUMER_SECRET ='---' OAUTH_TOKEN = '---' OAUTH_TOKEN_SECRET = '---'

auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET)

twitter_api = twitter.Twitter(auth=auth)

print "oh hi!" print twitter_api print "aw yeah"


oh hi! <twitter.api.Twitter object at 0x3d45110> aw yeah


So, that seems correct. However on example 2, I'm executing the following to get a URLError:


WORLD_WOE_ID = 1 US_WOE_ID = 23424977

world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID) us_trends = twitter_api.trends.place(_id=US_WOE_ID)

print world_trends print print us_trends



URLError Traceback (most recent call last) <ipython-input-22-992b7945297b> in <module>() 2 US_WOE_ID = 23424977 3 ----> 4 world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID) 5 us_trends = twitter_api.trends.place(_id=US_WOE_ID) 6

/usr/local/lib/python2.7/dist-packages/twitter/api.pyc in call(self, **kwargs) 201 202 req = urllib_request.Request(uriBase, body, headers) --> 203 return self._handle_response(req, uri, arg_data, _timeout) 204 205 def _handle_response(self, req, uri, arg_data, _timeout=None):

/usr/local/lib/python2.7/dist-packages/twitter/api.pyc in _handle_response(self, req, uri, arg_data, _timeout) 208 kwargs['timeout'] = _timeout 209 try: --> 210 handle = urllib_request.urlopen(req, **kwargs) 211 if handle.headers['Content-Type'] in ['image/jpeg', 'image/png']: 212 return handle

/usr/lib/python2.7/urllib2.pyc in urlopen(url, data, timeout) 124 if _opener is None: 125 _opener = build_opener() --> 126 return _opener.open(url, data, timeout) 127 128 def install_opener(opener):

/usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout) 398 req = meth(req) 399 --> 400 response = self._open(req, data) 401 402 # post-process response

/usr/lib/python2.7/urllib2.pyc in _open(self, req, data) 416 protocol = req.get_type() 417 result = self._call_chain(self.handle_open, protocol, protocol + --> 418 '_open', req) 419 if result: 420 return result

/usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, _args) 376 func = getattr(handler, meth_name) 377 --> 378 result = func(_args) 379 if result is not None: 380 return result

/usr/lib/python2.7/urllib2.pyc in https_open(self, req) 1213 1214 def https_open(self, req): -> 1215 return self.do_open(httplib.HTTPSConnection, req) 1216 1217 https_request = AbstractHTTPHandler.dorequest

/usr/lib/python2.7/urllib2.pyc in do_open(self, http_class, req) 1175 except socket.error, err: # XXX what error? 1176 h.close() -> 1177 raise URLError(err) 1178 else: 1179 try:

URLError: <urlopen error [Errno -3] Temporary failure in name resolution>


Any idea what I'm missing here? Happy to provide any information you might need.

Thanks in advance!

ptwobrussell commented 10 years ago

To be honest, I don't think you're missing anything at all. You are using the code exactly as provided in the VM as provided, right? The URLError that you're seeing implies that there is a DNS error happening for some reason, which could be related to a networking issue. A few questions that might help us work this out (in case it's not just a temporary networking glitch that will take care of itself)

By the way, I just re-ran the code, and it works fine (as expected). My guess is that there is just a little networking issue we have to work out (if not a temporary glitch somewhere - unlikely, but possible)

philrenaud commented 10 years ago

URLError Traceback (most recent call last) <ipython-input-2-212f940f2b89> in <module>() 16 17 twitter_api = twitter.Twitter(auth=auth) ---> 18 twitter_api.users.lookup(screen_name="SocialWebMining") 19 # Nothing to see by displaying twitter_api except that it's now a 20 # defined variable

/usr/local/lib/python2.7/dist-packages/twitter/api.pyc in call(self, **kwargs) 201 202 req = urllib_request.Request(uriBase, body, headers) --> 203 return self._handle_response(req, uri, arg_data, _timeout) 204 205 def _handle_response(self, req, uri, arg_data, _timeout=None):

/usr/local/lib/python2.7/dist-packages/twitter/api.pyc in _handle_response(self, req, uri, arg_data, _timeout) 208 kwargs['timeout'] = _timeout 209 try: --> 210 handle = urllib_request.urlopen(req, **kwargs) 211 if handle.headers['Content-Type'] in ['image/jpeg', 'image/png']: 212 return handle

/usr/lib/python2.7/urllib2.pyc in urlopen(url, data, timeout) 124 if _opener is None: 125 _opener = build_opener() --> 126 return _opener.open(url, data, timeout) 127 128 def install_opener(opener):

/usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout) 398 req = meth(req) 399 --> 400 response = self._open(req, data) 401 402 # post-process response

/usr/lib/python2.7/urllib2.pyc in _open(self, req, data) 416 protocol = req.get_type() 417 result = self._call_chain(self.handle_open, protocol, protocol + --> 418 '_open', req) 419 if result: 420 return result

/usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, _args) 376 func = getattr(handler, meth_name) 377 --> 378 result = func(_args) 379 if result is not None: 380 return result

/usr/lib/python2.7/urllib2.pyc in https_open(self, req) 1213 1214 def https_open(self, req): -> 1215 return self.do_open(httplib.HTTPSConnection, req) 1216 1217 https_request = AbstractHTTPHandler.dorequest

/usr/lib/python2.7/urllib2.pyc in do_open(self, http_class, req) 1175 except socket.error, err: # XXX what error? 1176 h.close() -> 1177 raise URLError(err) 1178 else: 1179 try:

URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

ptwobrussell commented 10 years ago

Phil - it looks like the error is exactly the same (URLError: <urlopen error [Errno -3] Temporary failure in name resolution>), indicating that something isn't resolving properly with the DNS lookup to the https address.

My guess is that this would have something to do with the coffee shop network, but please get back in touch with me once you try it at home so that I can rest assured that you are squared away. If you aren't, I'll do my best to help you troubleshoot remotely.

The good news is that this isn't a problem with the code, per se. But that's also the bad news since it makes the error all the more mysterious.

philrenaud commented 10 years ago

Looks like it was just the café's wifi - at home now, everything seems to be running smoothly.

twitter_api.users.lookup(screen_name="SocialWebMining") no longer throws an error, and world_trends / us_trends are coming back with real data.

Further, it's coming back much faster than the errors were firing at the café, making me think maybe they're throttling / maybe I need to find a new source of coffee.

Thanks a million for your help!

ptwobrussell commented 10 years ago

My pleasure! Please keep me in the loop with your social web mining activities. (And please consider leaving an AMZN review once you've formed an honest opinion about the book? It would be really helpful to me...)

philrenaud commented 10 years ago

Of course on both counts!

chiraz commented 10 years ago

I had the same problem with Example 1.2 when using a domestic dialup connection at home, but then it worked fine when I ran it with the wifi connection at work.

rajkumardash05 commented 10 years ago

Hi, I am facing the same problem with example 1.2 and onwards. I set up the IPython Notebook and tried to run the examples but it threw this error. However, the same code works fine in a Python Interpreter in the same computer with the same internet connection. Is there any setup related issue in the Appendix A?

ptwobrussell commented 10 years ago

I sounds as though there are some network settings that are preventing your VM from reaching the network.

What are the details regarding your host system? Versions of OS and installed software?

And did you follow the Appendix A instructions exactly as prescribed?

On Apr 13, 2014, at 9:38 AM, rajkumardash05 notifications@github.com wrote:

Hi, I am facing the same problem with example 1.2 and onwards. I set up the IPython Notebook and tried to run the examples but it threw this error. However, the same code works fine in a Python Interpreter in the same computer with the same internet connection. Is there any setup related issue in the Appendix A?

— Reply to this email directly or view it on GitHub.

rajkumardash05 commented 10 years ago

I followed both the text and video instructions provided in the appendix A and download all the latest versions of the required softwares. Vagrant 1.5.2, VirtualBox 4.3.10-93012 and Git-1.9.2. I am running 64-bit windows 7. I followed the same instructions at my University desktop and got everything fine there. However, it is not working from my laptop at home(Probably I need to bring the laptop to university to check it). I have an adsl broadband connection at my home. It might be the problem of DNS setting but I can't figure it out. This is the last line of the generated errors- URLError: <urlopen error [Errno -3] Temporary failure in name resolution>

ptwobrussell commented 10 years ago

@rajkumardash05 - It looks like you didn't provide the full error message. Can you provide the other details associated with the URLError?

Also, was the Python interpreter session that you say worked a couple of comments above run from inside of the VM (which would have required you to SSH into the box) or just on the Windows 7 environment from Command Prompt or Power Shell? This would be a hugely valuable clue.

rajkumardash05 commented 10 years ago

URLError Traceback (most recent call last)

in () 10 # to the URL itself as a special case keyword argument. 11 ---> 12 world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID) 13 us_trends = twitter_api.trends.place(_id=US_WOE_ID) 14 /usr/local/lib/python2.7/dist-packages/twitter/api.pyc in **call**(self, **kwargs) 237 238 req = urllib_request.Request(uriBase, body, headers) --> 239 return self._handle_response(req, uri, arg_data, _timeout) 240 241 def _handle_response(self, req, uri, arg_data, _timeout=None): /usr/local/lib/python2.7/dist-packages/twitter/api.pyc in _handle_response(self, req, uri, arg_data, _timeout) 244 kwargs['timeout'] = _timeout 245 try: --> 246 handle = urllib_request.urlopen(req, **kwargs) 247 if handle.headers['Content-Type'] in ['image/jpeg', 'image/png']: 248 return handle /usr/lib/python2.7/urllib2.pyc in urlopen(url, data, timeout) 124 if _opener is None: 125 _opener = build_opener() --> 126 return _opener.open(url, data, timeout) 127 128 def install_opener(opener): /usr/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout) 398 req = meth(req) 399 --> 400 response = self._open(req, data) 401 402 # post-process response /usr/lib/python2.7/urllib2.pyc in _open(self, req, data) 416 protocol = req.get_type() 417 result = self._call_chain(self.handle_open, protocol, protocol + --> 418 '_open', req) 419 if result: 420 return result /usr/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, _args) 376 func = getattr(handler, meth_name) 377 --> 378 result = func(_args) 379 if result is not None: 380 return result /usr/lib/python2.7/urllib2.pyc in https_open(self, req) 1213 1214 def https_open(self, req): -> 1215 return self.do_open(httplib.HTTPSConnection, req) 1216 1217 https_request = AbstractHTTPHandler.do_request_ /usr/lib/python2.7/urllib2.pyc in do_open(self, http_class, req) 1175 except socket.error, err: # XXX what error? 1176 h.close() -> 1177 raise URLError(err) 1178 else: 1179 try: URLError: This is the full error message generated. The interpreter (Active Python 2.7 as suggested in the first edition of your book) was run separately outside the VM. Thanks