YQLResponseMalformedError: Response malformed on yahoo_finance? - python

yahoo_finance's get_historical function has been working fine for me until yesterday.
Now it just keeps giving me YQLResponseMalformedError every time I try to call get_historical. Any ideas? I literally did nothing new with the code.
from yahoo_finance import Share
yahoo = Share('YHOO')
yahoo.refresh()
yahoo.get_historical('2014-04-26', '2014-04-29')
---------------------------------------------------------------------------
YQLResponseMalformedError Traceback (most recent call last)
<ipython-input-8-fbc20f9b6d26> in <module>()
----> 1 yahoo.get_historical('2014-04-26', '2014-04-29')
/Users/anjian/anaconda/lib/python2.7/site-packages/yahoo_finance-1.4.0-py2.7.egg/yahoo_finance/__init__.pyc in get_historical(self, start_date, end_date)
340 try:
341 query = self._prepare_query(table='historicaldata', startDate=s, endDate=e)
--> 342 result = self._request(query)
343 if isinstance(result, dict):
344 result = [result]
/Users/anjian/anaconda/lib/python2.7/site-packages/yahoo_finance-1.4.0-py2.7.egg/yahoo_finance/__init__.pyc in _request(self, query)
123 raise YQLQueryError(response['error']['description'])
124 except KeyError:
--> 125 raise YQLResponseMalformedError()
126 else:
127 if self._is_error_in_results(results):
YQLResponseMalformedError: Response malformed.

Answered here: Python and Yahoo finance weird "YQLQueryError(response['error']['description'])" get_historical

Related

KPLR: JSONDecodeError: Expecting value: line 1 column 1 (char 0)

I am trying to follow the KPLR tutorial run in Google Colab the last code snippet on the page:
import kplr
client = kplr.API()
# Find the target KOI.
koi = client.koi(952.01)
# Get a list of light curve datasets.
lcs = koi.get_light_curves(short_cadence=False, fetch=True, clobber=True)
# Loop over the datasets and read in the data.
time, flux, ferr, quality = [], [], [], []
for lc in lcs:
with lc.open() as f:
# The lightcurve data are in the first FITS HDU.
hdu_data = f[1].data
time.append(hdu_data["time"])
flux.append(hdu_data["sap_flux"])
ferr.append(hdu_data["sap_flux_err"])
quality.append(hdu_data["sap_quality"])
When I run this though, I receive the following error:
JSONDecodeError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/kplr/api.py in mast_request(self, category, adapter, sort, mission, **params)
197 try:
--> 198 result = json.loads(txt)
199 except ValueError:
7 frames
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
APIError Traceback (most recent call last)
/usr/local/lib/python3.7/dist-packages/kplr/api.py in mast_request(self, category, adapter, sort, mission, **params)
200 full_url = handler.geturl() + "?" + urllib.parse.urlencode(params)
201 raise APIError(code, full_url,
--> 202 "No JSON object could be decoded.\n" + txt)
203
204 # Fake munge the types if no adapter was provided.
Any suggestions?

pywren and twint - Tweet download

The following code takes a username and scrapes their twitter history from a given date
import pandas as pd
import twint
import pywren
def scrape_user(username):
c = twint.Config()
c.Username = username
c.Lang = 'es'
c.Since = '2021-04-28'
c.Hide_output = True
c.Pandas = True
twint.run.Search(c)
return twint.storage.panda.Tweets_df
When I run the function, I get the intended result i.e., a Pandas dataframe e.g., scrape_user("DeLaCalleHum"). However, when I use pywren (on even a single username)
pwex = pywren.default_executor()
futures = pwex.map(scrape_user, "DeLaCalleHum")
tweet_list = pywren.get_all_results(futures)
I get this error.
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-31-15f9e00ead75> in <module>
----> 1 wc_list = pywren.get_all_results(futures)
~/macs30123/lib/python3.7/site-packages/pywren/wren.py in get_all_results(fs)
117 """
118 wait(fs, return_when=ALL_COMPLETED)
--> 119 return [f.result() for f in fs]
~/macs30123/lib/python3.7/site-packages/pywren/wren.py in <listcomp>(.0)
117 """
118 wait(fs, return_when=ALL_COMPLETED)
--> 119 return [f.result() for f in fs]
~/macs30123/lib/python3.7/site-packages/pywren/future.py in result(self, timeout, check_only, throw_except, storage_handler)
146 if self._state == JobState.error:
147 if throw_except:
--> 148 raise self._exception
149 else:
150 return None
OSError: [Errno 28] No space left on device
What am I doing wrong? I would appreciate any help.
After some time I found the answer. I can automatically parallelize such function calls in PyWren as long as I add the ComprehendFullAccess policy to my pywren_exec_role_1 role in IAM

How do I get a forex ticker working in yahoo finance?

When I use any ticker that isn't a forex pair it works. But with the fx tickers it doesn't. I end up getting an error.
from yahoo_fin.stock_info import get_live_price
get_live_price('EURUSD=X')
Below Is the error I encountered.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-15-a1b6fb5ddbd7> in <module>
4
5 #Stock = input('Stock:')
----> 6 get_live_price('EURUSD=X')
7 #stockprice = get_live_price(str(Stock))
8
//anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_live_price(ticker)
336 '''
337
--> 338 df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
339
340
//anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_data(ticker, start_date, end_date, index_as_date)
58 html = html.decode()
59
---> 60 start = html.index('"HistoricalPriceStore"')
61 end = html.index("firstTradeDate")
62
ValueError: substring not found
any ideas? It' clearly something to do with the ticker. When I use 'nflx' or 'aapl' it works like a charm. It's with forex that it seems to misbehave?
That is the same error you get if the tag is made up trash.
Could you be trying to request a malformed tag/ticker?
In [12]: from yahoo_fin.stock_info import get_live_price
...: get_live_price('poop')
...:
...:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-12-17c9a30a78a2> in <module>
1 from yahoo_fin.stock_info import get_live_price
----> 2 get_live_price('poop')
3
~/anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_live_price(ticker)
336 '''
337
--> 338 df = get_data(ticker, end_date = pd.Timestamp.today() + pd.DateOffset(10))
339
340
~/anaconda3/lib/python3.7/site-packages/yahoo_fin/stock_info.py in get_data(ticker, start_date, end_date, index_as_date)
58 html = html.decode()
59
---> 60 start = html.index('"HistoricalPriceStore"')
61 end = html.index("firstTradeDate")
62
ValueError: substring not found

Python Datareader cannot extract stock data from Morningstar

I'm a beginner in python working with stock data. This morning I was able to extract stock data from the morningstar website fine, however when I try to do so now I receive the following error message shown below. What could be causing this issue and what can I do to fix it? Thanks
Exception Traceback (most recent call last)
in ()
63 '''
64
---> 65 df=web.DataReader('MMM','morningstar', start, end)
66 print(df)
67 stockname=df.to_csv('mmm.csv')
~\Documents\New folder (2)\lib\site-packages\pandas_datareader\data.py in DataReader(name, data_source, start, end, retry_count, pause, session, access_key)
389 return MorningstarDailyReader(symbols=name, start=start, end=end,
390 retry_count=retry_count, pause=pause,
--> 391 session=session, interval="d").read()
392 elif data_source == 'robinhood':
393 return RobinhoodHistoricalReader(symbols=name, start=start, end=end,
~\Documents\New folder (2)\lib\site-packages\pandas_datareader\mstar\daily.py in read(self)
217 "type %s" % type(self.symbols))
218
--> 219 df = self._dl_mult_symbols(symbols=symbols)
220 if len(df.index.levels[0]) == 0:
221 raise ValueError("None of the provided symbols were valid")
~\Documents\New folder (2)\lib\site-packages\pandas_datareader\mstar\daily.py in _dl_mult_symbols(self, symbols)
128 else:
129 raise Exception("Request Error!: %s : %s" % (
--> 130 resp.status_code, resp.reason))
131
132 time.sleep(self.pause)
Exception: Request Error!: 404 : Not Found
Seems like a provider issue. The API isn't documented (I believe it came from here), so it's difficult to tell with certainty what changes were made / if it was taken down.
For now, I would recommend using other sources such as AlphaVantage, Quandl, or IEX. The simplest is IEX, which does not require an API key
df = web.DataReader('MMM', 'IEX', start, end)

Python ipwhois ASN Registry Error

I am using ipwhois for the first time. Running the basic usage example with a Google IP address works:
from ipwhois import IPWhois
obj = IPWhois('74.125.225.229')
results = obj.lookup_rdap(depth=1)
Any other IP address results in this error:
ASNRegistryError Traceback (most recent call last)
<ipython-input-62-03afc25be9cd> in <module>()
----> 1 results = obj.lookup_rdap(depth=1)
~\_installed\anaconda\envs\geocode\lib\site-packages\ipwhois\ipwhois.py in lookup_rdap(self, inc_raw, retry_count, depth, excluded_entities, bootstrap, rate_limit_timeout, asn_alts, extra_org_map, inc_nir, nir_field_list, asn_methods, get_asn_description)
306 inc_raw=inc_raw, retry_count=retry_count, asn_alts=asn_alts,
307 extra_org_map=extra_org_map, asn_methods=asn_methods,
--> 308 get_asn_description=get_asn_description
309 )
310
~\_installed\anaconda\envs\geocode\lib\site-packages\ipwhois\asn.py in lookup(self, inc_raw, retry_count, asn_alts, extra_org_map, asn_methods, get_asn_description)
569 if asn_data is None:
570
--> 571 raise ASNRegistryError('ASN lookup failed with no more methods to '
572 'try.')
573
ASNRegistryError: ASN lookup failed with no more methods to try.
I attempted to switch the lookup method to ARIN with bootstrap=True to no avail. How do I remedy this error?

Categories