Skip to content

local variable 'rs' referenced before assignment error #9991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
galfaroi opened this issue Apr 26, 2015 · 5 comments
Closed

local variable 'rs' referenced before assignment error #9991

galfaroi opened this issue Apr 26, 2015 · 5 comments
Labels
IO Data IO issues that don't fit into a more specific label

Comments

@galfaroi
Copy link

Hope you can help with the following error (thanks):
(with any financial data source, after I upgraded to v0.16 because yahoo finance was not working 0.14)

$goog=web.DataReader('GOOG', data_source='google', start='3/14/2009', end = '4/14/2014')

anaconda/lib/python2.7/site-packages/pandas/io/data.pyc in _retry_read_url(url, retry_count, pause, name)
175 #Get rid of unicode characters in index name.
176 try:
--> 177 rs.index.name = rs.index.name.decode('unicode_escape').encode('ascii', 'ignore')
178 except AttributeError:
179 #Python 3 string has no decode method.

UnboundLocalError: local variable 'rs' referenced before assignment

In [33]: pd.version
Out[33]: '0.16.0'

@evanpw
Copy link
Contributor

evanpw commented Apr 26, 2015

This is fixed in pandas-datareader: https://github.com/pydata/pandas-datareader. It should be good in version 0.1.1

@galfaroi
Copy link
Author

After installing pandas_datareader it with pip:

In [1]: import pandas_datareader.data as web

In [2]: import datetime

In [3]: start = datetime.datetime(2010, 1, 1)

In [4]: end = datetime.datetime(2013, 1, 27)

In [5]: f = web.DataReader("F", 'yahoo', start, end)
183
184 raise IOError("after %d tries, %s did not "
--> 185 "return a 200 for url %r" % (retry_count, name, url))
186
187

IOError: after 3 tries, Yahoo! did not return a 200 for url 'http://ichart.finance.yahoo.com/table.csv?s=F&a=0&b=1&c=2010&d=0&e=27&f=2013&g=d&ignore=.csv'

do I missing something?
Thanks!

@evanpw
Copy link
Contributor

evanpw commented Apr 27, 2015

This looks like a problem outside of pandas (are you behind a proxy / firewall?). Try this directly:

import urllib2
urllib2.urlopen('http://ichart.finance.yahoo.com/table.csv?s=F&a=0&b=1&c=2010&d=0&e=27&f=201=d&ignore=.csv')

If that doesn't work, then the problem is just that your machine can't connect to yahoo.

@galfaroi
Copy link
Author

I don't have a proxy/firewall that I am aware of, I can download the file directly... and also I tried with another network and I Have the same following 404 error:

In [8]: urllib2.urlopen('http://ichart.finance.yahoo.com/table.csv?s=F&a=0&b=1&c=2010&d=0&e=27&f=201=d&ignore=.csv')

HTTPError Traceback (most recent call last)
in ()
----> 1 urllib2.urlopen('http://ichart.finance.yahoo.com/table.csv?s=F&a=0&b=1&c=2010&d=0&e=27&f=201=d&ignore=.csv')

/home/german/anaconda/lib/python2.7/urllib2.pyc in urlopen(url, data, timeout, cafile, capath, cadefault, context)
152 else:
153 opener = _opener
--> 154 return opener.open(url, data, timeout)
155
156 def install_opener(opener):

/home/german/anaconda/lib/python2.7/urllib2.pyc in open(self, fullurl, data, timeout)
435 for processor in self.process_response.get(protocol, []):
436 meth = getattr(processor, meth_name)
--> 437 response = meth(req, response)
438
439 return response

/home/german/anaconda/lib/python2.7/urllib2.pyc in http_response(self, request, response)
548 if not (200 <= code < 300):
549 response = self.parent.error(
--> 550 'http', request, response, code, msg, hdrs)
551
552 return response

/home/german/anaconda/lib/python2.7/urllib2.pyc in error(self, proto, _args)
473 if http_err:
474 args = (dict, 'default', 'http_error_default') + orig_args
--> 475 return self._call_chain(_args)
476
477 # XXX probably also want an abstract factory that knows when it makes

/home/german/anaconda/lib/python2.7/urllib2.pyc in _call_chain(self, chain, kind, meth_name, _args)
407 func = getattr(handler, meth_name)
408
--> 409 result = func(_args)
410 if result is not None:
411 return result

/home/german/anaconda/lib/python2.7/urllib2.pyc in http_error_default(self, req, fp, code, msg, hdrs)
556 class HTTPDefaultErrorHandler(BaseHandler):
557 def http_error_default(self, req, fp, code, msg, hdrs):
--> 558 raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
559
560 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 404: Not Found

@jreback
Copy link
Contributor

jreback commented Apr 28, 2015

fixed here pydata/pandas-datareader#25

@jreback jreback closed this as completed Apr 28, 2015
@jreback jreback added IO Data IO issues that don't fit into a more specific label Data Reader labels Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

No branches or pull requests

3 participants