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
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.
I'm starting on a project using Clarifai. However, when I define the app, I'm getting a key error:
from clarifai.rest import ClarifaiApp
from clarifai.rest import Image as ClImage
import os
from glob import glob
api_key = 'my api key'
app = ClarifaiApp(api_key=api_key) # Error occurs here
model_id = 'model id'
concepts = ['concept1', 'concept2', 'concept3']
Traceback (most recent call last):
File "C:\Users\crayo\uShoe\main.py", line 6, in <module>
app = ClarifaiApp(api_key=api_key)
File "C:\Users\user\project\venv\lib\site-packages\clarifai\rest\client.py", line 124, in __init__
self.models = Models(self.api, self.solutions) # type: Models
File "C:\Users\user\project\venv\lib\site-packages\clarifai\rest\client.py", line 1068, in __init__
self.model_id_cache = self.init_model_cache()
File "C:\Users\user\project\venv\lib\site-packages\clarifai\rest\client.py", line 1088, in init_model_cache
model_type = m.output_info['type']
KeyError: 'type'
I'm not sure what's causing this error, so if someone could provide input I'd appreciate it! Thanks!
You are using the deprecated Python REST package: https://github.com/Clarifai/clarifai-python. Please replace your code with the new & updated Python gRPC client: https://github.com/Clarifai/clarifai-python-grpc
Make sure to uninstall the REST package to avoid conflicts.
You can find our API docs & code snippets here: https://docs.clarifai.com
I am trying to use PyGitHub to automate updating files in a special repository. This special repo consists of parts of several other repos so I am using a GitHub webhook to cause it to be updated whenever any of the other repos are updated. I am running into a problem when a file is added to any of the other repos. In this case, I need to add a file to the special repo. Here is a snippet of the code
from github import GitHub
ACCESS_TOKEN = '...'
ORGANIZATION = '...'
REPONAME = '...'
gh = Github(ACCESS_TOKEN)
org = gh.get_organization(ORGANIZATION)
repo = org.get_repo(REPONAME)
path = <path-to-file-in-special-repo>
message = <commit-message-for-create-file>
contents = OtherRepo.get_contents(<<path-to-file-in-other-repo>).decoded_content.decode('utf-8')
repo.create_file(path, message, contents)
This is giving me the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/github/Repository.py", line 2090, in create_file
headers, data = self._requester.requestJsonAndCheck(
File "/usr/local/lib/python3.9/site-packages/github/Requester.py", line 353, in requestJsonAndCheck
return self.__check(
File "/usr/local/lib/python3.9/site-packages/github/Requester.py", line 378, in __check
raise self.__createException(status, responseHeaders, output)
github.GithubException.GithubException: 422 {"message": "Invalid request.\n\n\"sha\" wasn't supplied.", "documentation_url": "https://docs.github.com/rest/reference/repos#create-or-update-file-contents"}
If I just do:
repo.create_file(path, 'test', 'test')
it works.
Can anyone tell me what I am doing wrong?
I have discovered what the problem is.
Because of the way I was testing my program the file I was trying to create was one previously deleted from the repo. What I needed to do was repo.update_file and, not repo.create_file.
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')
I've been trying to post the readings from my Rpi on Twitter using tweepy, but first I wanted to check if tweepy was working properly, but it's not.
I installed the packages properly, but when I'm trying to run a simple code to post something, I got an error (Yes, I already created an app and have the 4 credentials).
The code I'm trying to run:
import tweepy
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
single_tweet = 'hello world'
api.update_status(single_tweet)
print "successfully Updated"
I got this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-armv6l/egg/tweepy/api.py", line 193, in update_status
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 239, in _call
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 223, in execute
tweepy.error.TweepError: [{u'message': u'media_ids parameter is invalid.', u'code': 44}]
I'm runing the python code that is in the tweepy folder "oauth.py" (adding it my credentials)
$ sudo python oauth.py
RapiCARA
Traceback (most recent call last):
File "oauth.py", line 34, in <module>
api.update_status(' Hello world ')
File "build/bdist.linux-armv6l/egg/tweepy/api.py", line 193, in update_status
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 239, in _call
File "build/bdist.linux-armv6l/egg/tweepy/binder.py", line 223, in execute
tweepy.error.TweepError: [{u'message': u'media_ids parameter is invalid.', u'code': 44}]
The code in that file, you can find it in its origial source: Tweepy in GITHUB
Any help/advice please?
The first positional argument to the update_status() method is interpreted as the media_ids parameter. You need to explicitly name your status parameter to avoid this:
api.update_status(status=single_tweet)
This is a recent change in Tweepy and it looks like their documentation hasn't been updated yet to reflect this.
The different signature has been reported as a bug for the project.
The bug was fixed in August 2015; version 3.5 or newer of Tweepy once again treat the first positional argument as the status parameter.