AttributeError: 'Spotify' object has no attribute 'current_user_saved_tracks' - python

Using Spotipy and am attempting to 'current_user_recently_played'
token = util.prompt_for_user_token(username, scope = scope, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri)
sp = spotipy.Spotify(auth = token)
saved = sp.current_user_saved_tracks()
print(saved)
recent = sp.current_user_recently_played()
print(recent)
sp.current_user_saved_tracks() runs just fine, sp.current_user_recently_played() apparently doesn't exist even though it is clearly in the documentation https://spotipy.readthedocs.io/en/latest/#more-examples.
Running - v2.4.4 - January 4, 2017
Thanks ahead of time.
Traceback (most recent call last):
File "C:\Users\Martin\Google Drive\Python\Spotify\try_req.py", line 19, in <module>
recent = sp.current_user_recently_played()
AttributeError: 'Spotify' object has no attribute 'current_user_recently_played'

You're going to have to get the code manually. The installation via pip is outdated.
Navigate to where you installed Spotipy (for me it was C:\Users\[myName]\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\spotipy), open client.py and replace the code with the newer code found here.

This is due to the outdated version on PyPi, as Mangohero1 already pointed out. The following method is probably easier than manually changing code.
You can install the latest code like this:
pip install git+https://github.com/plamere/spotipy.git --upgrade
(source)

Related

How to properly install csdtoolbox-remote?

I am having trouble installing the cdstoolbox-remote on my Linux machine (tried both Ubuntu and Debian). I installed it using pip:
pip install cdstoolbox-remote
Which successfully installs the module, but I can't import the module in Python. Importing the module causes the following error:
>>> import cdstoolbox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/an/miniconda2/envs/tools/lib/python3.7/site-packages/cdstoolbox/__init__.py",
line 8, in <module>
with open(__main__.__file__) as f:
AttributeError: module '__main__' has no attribute '__file__'
What can be done to get it working?
Do you really need cdstoolbox-remote? The standard API for downloading data from CDS would be cdsapi, which can be installed using
pip install cdsapi
or using conda (https://anaconda.org/conda-forge/cdsapi)
I also just tried installing cdstoolbox-remote and got the same problem. But as it is flagged as experimental I even consider it to be possible that the current version is not a stable version.
And cdsapi seems to work.
Actually, the CDSAPI can also be used to execute workflows as follows:
import cdsapi
c = cdsapi.Client()
with open("workflow.py") as f:
code = f.read()
r = c.workflow(code)
print(c.download(r))
For more, read this thread on the Copernicus services documentation.

How to fix "'pandas.compat' has no attribute 'string_types'" error in python3

I am watching this tutorial where I am trying to use iexfinance to get stock data. You have the option to choose the data type when requesting the data, I chose "pandas". When I run the built-in function I get an error that reads AttributeError: module 'pandas.compat' has no attribute 'string_types'
I am using python 3.7. I have uninstalled and reinstalled both iexfinance and pandas. I also created and IEX cloud account and passed in a secret key like the documentation states, but the same error. The tutorial doesn't mention any of these steps and its confusing why his works and mine isn't.
I have tried to make the code simpler by following examples on the website: Even when running:
from iexfinance.stocks import Stock
df = Stock("AAPL", output_format="pandas")
print(df.get_quote().head())
The error persists
The expected output is:
AAPL
avgTotalVolume 30578248
calculationPrice close
change -0.58
changePercent -0.00298
close 207.27
The output I am receiving is:
Traceback (most recent call last):
File "app.py", line 18, in <module>
df = Stock("AAPL", output_format="pandas")
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/iexfinance/stocks/base.py", line 45, in __init__
self.symbols = list(map(lambda x: x.upper(), _handle_lists(symbols)))
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/iexfinance/utils/__init__.py", line 43, in _handle_lists
if isinstance(l, (compat.string_types, int)):
AttributeError: module 'pandas.compat' has no attribute 'string_types'
You can try reverting the pandas version to 0.24.2 as a workaround:
pip install pandas==0.24.2
At this point I am still not sure if a bug in pandas or something else.
EDIT: Probably the iexfinance is using some internals in Pandas, and pandas has undergone a major change dropping python 2 and all the compatibility code.
This is also already on their issue tracker:
https://github.com/addisonlynch/iexfinance/issues/163
The method about:
pip install pandas==0.24.2
is right~ try this.
To date 2 October 2019, just update iexfinance to the latest version (0.4.3) and the problem is solved. Do this:
pip install iexfinance --upgrade

Facebook-sdk python module has no attribute GraphAPI

After installing the facebook-sdk module here, and looking at other solutions here and elsewhere, I keep getting this error:
Traceback (most recent call last):
File "facebook.py", line 1, in <module>
import facebook
File "/home/facebook/facebook.py", line 3, in <module>
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
AttributeError: 'module' object has no attribute 'GraphAPI'
For this very simple python code to authenticate...
import facebook
graph = facebook.GraphAPI(access_token='ACCESS TOKEN HERE')
print 'Workinnnn'
It says my module is installed and up to date, and I have installed both within (as suggested) a virtualenv and outside, and still get the error. I also definitely HAVE the module in usr/local/lib/python etc. dist packages... and it contains the class GraphAPI
Has anyone got a suggestion either:
1) What might be going wrong?
2) What to try to fix it? UNinstall something?
3) If there is another way other than pip to install the module... I don't normally use pip (but definitely have it installed and installed facebook-sdk from it) so if there's another way then I'd like to try...
Cheers :/
Solution = don't name your script the same as your module.
I'm an idiot, sigh...

installing and using python-oauth2

I installed oauth2:
$ pip install oauth2
But running the python-oauth2/example/client.py returns:
Traceback (most recent call last):
File "client.py", line 31, in <module>
import oauth.oauth as oauth
ImportError: No module named oauth.oauth
I tested pip freeze:
oauth2==1.5.211
Thanks in advance
As it turns out, the example directory in the oauth2 package should be ignored. It is broken code as far as the package is concerned.
See these issues for examples of other people discovering this:
https://github.com/simplegeo/python-oauth2/issues/33
https://github.com/simplegeo/python-oauth2/issues/12
https://github.com/simplegeo/python-oauth2/pull/64
The last one is a pull request that includes new examples to use instead.

'module' object has no attribute 'Twitter'

I am trying to follow the example on page 5 of the book: Mining the Social Web, from O'Reilly. I am coming across the following error:
>>> import twitter
>>> twitter_api = twitter.Twitter(domain="api.twitter.com", api_version='1')
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'module' object has no attribute 'Twitter'
What might be going on?
Check the value of twitter.__file__ (after you've imported twitter). My guess is either you somehow got a broken version of twitter, or you've created a file called twitter.py in the same directory you're running from that's blocking the installed module from loading.
If twitter.__file__ looks good (points to where your installed modules should be instead of the local dir), try easy_install -U twitter to reinstall it.
Works for me. I installed twitter through easy_install, which installed the latest version (1.6.1). dir(twitter) also lists Twitter here.
You could remove the twitter package from site-packages and try reinstalling again.

Categories

Resources