I had made a private quandl account and received my quandl Api key but how to add the key to my request in python?
My Code:
import pandas as pd
import quandl
df = quandl.get('EOD/V')
print(df.head())
Error:
Traceback (most recent call last):
File "C:\Users\qasim\Documents\python_machine_learning\regression.py", line 4, in <module>
df = quandl.get('EOD/V')
File "C:\Python27\lib\site-packages\quandl\get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "C:\Python27\lib\site-packages\quandl\model\dataset.py", line 47, in data
return Data.all(**updated_options)
File "C:\Python27\lib\site-packages\quandl\operations\list.py", line 14, in all
r = Connection.request('get', path, **options)
File "C:\Python27\lib\site-packages\quandl\connection.py", line 36, in request
return cls.execute_request(http_verb, abs_url, **options)
File "C:\Python27\lib\site-packages\quandl\connection.py", line 44, in execute_request
cls.handle_api_error(response)
File "C:\Python27\lib\site-packages\quandl\connection.py", line 85, in handle_api_error
raise klass(message, resp.status_code, resp.text, resp.headers, code)
quandl.errors.quandl_error.ForbiddenError: (Status 403) (Quandl Error QEPx05) You have attempted to view a premium database in anonymous mode, i.e., without providing a Quandl key. Please register for a free Quandl account, and then include your API key with your requests.
[Finished in 6.0s]
From the Configuration doc part, you can set it with ApiConfig.api_key :
import quandl
quandl.ApiConfig.api_key = 'tEsTkEy123456789'
Also, from the quandl python doc, you can define additional optional arguments in the get method :
:param str api_key: Downloads are limited to 50 unless api_key is specified
So you could also use :
df = quandl.get('EOD/V', api_key='tEsTkEy123456789')
Simply give api key value in authtoken
import quandl
df = quandl.get('EOD/V', authtoken=='tEsTkEy123456789')
Related
Everyone. Today, I was creating a Twitter Bot in Python using the tweepy module, which works perfectly. I've observed that when I use a While True command to tweet anything, it will Tweet it at first, so show me an error here it is below.
Response(data={'id': '1522239311277486080', 'text': 'Alas, after a certain age every man is responsible for his face.-Albert Camus'}, includes={}, errors=[], meta={})
Traceback (most recent call last):
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\main.py", line 13, in <module>
response = client.create_tweet(text=Quotes.Quotes_Random)
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\venv\lib\site-packages\tweepy\client.py", line 824, in create_tweet
return self._make_request(
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\venv\lib\site-packages\tweepy\client.py", line 126, in _make_request
response = self.request(method, route, params=request_params,
File "C:\Users\varni\PycharmProjects\Twitter_Bot Version 1\venv\lib\site-packages\tweepy\client.py", line 99, in request
raise Forbidden(response)
tweepy.errors.Forbidden: 403 Forbidden
And here is the code-
import config
import tweepy
import Quotes
import time
client = tweepy.Client(consumer_key=config.API_KEY,
consumer_secret=config.API_SECRET,
access_token=config.ACCESS_TOKEN,
access_token_secret=config.ACCESS_TOKEN_SECRET)
while True:
# time.sleep(600)
response = client.create_tweet(text=Quotes.Quotes_Random)
print(response)
is there way to fix this error?
You're likely encountering this because you can't Tweet the exact same text you've already recently Tweeted.
Im following a tutorial on ML and quandl and have imported quandl and dependencies for python3. When I run
import quandl
data = quandl.get("EIA/PET_RWTC_D")
print(data.head())
I have a quandl account and this code is from the quandl python docs since I wanted to make sure the tutorial was not wrong (https://www.youtube.com/watch?v=JcI5Vnw0b2c&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v&index=2) (I made sure it was lowercase quandl for import since it differed due to the posted date of the video), I also tried with my api_key and using that arg in quandl.get()
I get the error:
Traceback (most recent call last):
File "ml_regression1.py", line 4, in <module>
quandl.get("EIA/PET_RWTC_D", authtoken="MyAuthTokenPlaceHolder")
File "/usr/local/lib/python3.5/dist-packages/quandl/get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "/usr/local/lib/python3.5/dist-packages/quandl/model/dataset.py", line 47, in data
return Data.all(**updated_options)
File "/usr/local/lib/python3.5/dist-packages/quandl/operations/list.py", line 14, in all
r = Connection.request('get', path, **options)
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 38, in request
return cls.execute_request(http_verb, abs_url, **options)
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 42, in execute_request
session = cls.get_session()
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 58, in get_session
adapter = HTTPAdapter(max_retries=cls.get_retries())
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 74, in get_retries
raise_on_status=False)
TypeError: __init__() got an unexpected keyword argument 'raise_on_status'
Any help would be great, thank you.
pip3 install --upgrade urllib3 solved the problem for me (urllib3 was not up to date).
see also https://stackoverflow.com/a/53375266/8496767
I'm pretty new to Python and I'm trying to connect to smartsheet with API.
I have ran "pip install smartsheet-python-sdk" and it installed smartsheet as I can find it under "lib"
This is code I have found and supposed to work(I replaced the token with the token)
# Import.
import smartsheet
# Instantiate smartsheet and specify access token value.
smartsheet = smartsheet.Smartsheet('Token_here')
# Get all columns.
action = smartsheet.Sheets.get_columns('Template for Bram', include_all=True)
columns = action.data
# For each column, print Id and Title.
for col in columns:
print(col.id)
print(col.title)
print('')
It shows this error:
Traceback (most recent call last):
File "C:\Users\bram\Desktop\smartsheet.py", line 2, in <module>
import smartsheet
File "C:\Users\bram\Desktop\smartsheet.py", line 5, in <module>
smartsheet = smartsheet.Smartsheet('token_here')
AttributeError: 'module' object has no attribute 'Smartsheet'
Now I'm not sure what my next step is. I think I have followed all of the appropriate steps. When I run import smartsheet by itself it won't error out.
What am I doing wrong?
Thank you
Update***
After using the code from the github page and implementing my token and sheet id I get this error:
Traceback (most recent call last):
File "C:\Users\bvanhout\Desktop\test23.py", line 58, in <module>
sheet = ss.Sheets.get_sheet(sheet_id)
File "C:\Python27\lib\site-packages\smartsheet\sheets.py", line 460, in get_sheet
response = self._base.request(prepped_request, expected, _op)
File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 178, in request
res = self.request_with_retry(prepped_request, operation)
File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 242, in request_with_retry
return self._request(prepped_request, operation)
File "C:\Python27\lib\site-packages\smartsheet\smartsheet.py", line 210, in _request
raise UnexpectedRequestError(rex.request, rex.response)
UnexpectedRequestError: (<PreparedRequest [GET]>, None)
# TODO: Update this with the ID of your sheet to update
sheet_id = 48568543424234
I printed ss and ss.Sheets and both do not reflect the actual token or sheet_id
>>> print (ss.Sheets)
<smartsheet.sheets.Sheets object at 0x0000000003874438>
I suspect the problem is that you are using a local variable with the same name as the module ('smartsheet')
Please take a look at the sample here: https://github.com/smartsheet-samples/python-read-write-sheet
I am trying to parse the information about applications form the itunes lookup tool for example https://itunes.apple.com/lookup?id=880047117.
Right now I am trying to open up a connection using requests, JSON and a JSON objects schema. However the schema keeps failing with the error:
Traceback (most recent call last):
File "parse_and_query.py", line 33, in <module>
details = get_app_details(880047117)
File "/usr/lib/python3.5/site-packages/jsonobjects/schema.py", line 87, in wrapper
return self.parse(func(*args, **kwargs))
File "/usr/lib/python3.5/site-packages/jsonobjects/fields.py", line 169, in parse
return self.run_validation(value)
File "/usr/lib/python3.5/site-packages/jsonobjects/fields.py", line 136, in run_validation
is_empty, value = self.validate_empty_values(value)
File "/usr/lib/python3.5/site-packages/jsonobjects/fields.py", line 105, in validate_empty_values
self.fail('required')
File "/usr/lib/python3.5/site-packages/jsonobjects/fields.py", line 165, in fail
raise ValidationError(msg.format(**kwargs), self.field_name)
jsonobjects.exceptions.ValidationError: ['This field is required.']
The schema is declared as it's own class object and instantiated but it continually fails. I have the ID's of apps that I would like to look up the JSON information on. If there is an easier way that I am missing please let me know, I don't have access to the iTunes API.
#!/usr/local/bin/python3.5
import json
import requests
import jsonobjects as jo
from jsonschema import Draft4Validator
class iTunesAppSchema(jo.Schema):
id = jo.IntegerField('trackId')
url = jo.Field('trackViewUrl')
name = jo.StringField('trackName')
rating = jo.FloatField('averageUserRating')
reviews = jo.IntegerField('userRatingCountForCurrentVersion')
version = jo.StringField('version')
bundle_id = jo.StringField('bundleId')
publisher_id = jo.IntegerField('artistId')
publisher_url = jo.Field('artistViewUrl')
publisher_name = jo.StringField('artistName')
categories = jo.ListField('genres', child=jo.StringField())
parser = iTunesAppSchema('results[0]')
#parser.as_decorator
def get_app_details(app_id):
url = 'https://itunes.apple.com/lookup?id={}'
return requests.get(url.format(app_id)).json()
# https://itunes.apple.com/lookup?id=880047117
details = get_app_details(880047117)
print(details)
Starting from stage one trying to connect to bitstamp.
I have a funded account and an api key.
I am trying the following:
import bitstamp.client
public_client = bitstamp.client.Public()
print(public_client.ticker()['volume'])
trading_client = bitstamp.client.Trading(username='userNameForWeb', key='apiKeyFromBitStamp', secret='myPasswordFromWeb')
print(trading_client.ticker()['volume'])
print(trading_client.account_balance()['fee'])
Yet getting the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "/Users/jasonmellone/Documents/PythonProjects/bitStamp.py", line 18, in <module>
print(trading_client.account_balance()['fee'])
File "/Library/Python/2.7/site-packages/bitstamp/client.py", line 197, in account_balance
return self._post("balance/", return_json=True)
File "/Library/Python/2.7/site-packages/bitstamp/client.py", line 47, in _post
return self._request(requests.post, *args, **kwargs)
File "/Library/Python/2.7/site-packages/bitstamp/client.py", line 80, in _request
raise BitstampError(error)
bitstamp.client.BitstampError: Invalid signature
I grabbed the code directly from the github project.
Happy to use other library for python, but looking for input.
Thanks!
trading_client = bitstamp.client.Trading(username='userNameForWeb', key='apiKeyFromBitStamp', secret='myPasswordFromWeb')
The secret should not be myPasswordFromWeb. The error clearly says you have an 'Invalid signature.'. The secret should be the api_secret key that bitstamp shows you only ONE TIME when you generate an API key. Generate a new API key and store the secret key it gives you. Your secret key will be almost (if not equally) as long as your API key. Hope this helps.