KeyError: 'type' Clarifai - python

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

Related

How to use PyGitHib repo.create_file

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 have a problem with os module in python

I've recently had a problem with (i think) the os module in python:
Traceback (most recent call last):
File "main.py", line 9, in <module>
api = getApi(os.environ['consumer_key'], os.environ['consumer_secret'], os.environ['access_token_key'], os.environ['access_token_secret'])
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\lib\os.py", line 681, in __getitem__
raise KeyError(key) from None
KeyError: 'consumer_key'
my code of main.py is:
from config import getApi
import os
import sys
import time
print()
api = getApi(os.environ['consumer_key'], os.environ['consumer_secret'], os.environ['access_token_key'], os.environ['access_token_secret'])
my code of config.py is
import twitter
import os
def getApi(consumer_key, consumer_secret, access_token_key, access_token_secret):
return twitter.Api(consumer_key='*********',
consumer_secret='*********',
access_token_key='*********',
access_token_secret='*********')
Send tweets with the postUpdate is possible if I write the keys in the main.py but when I put the keys in the config.py, it don't works
Can anyone help me please ?
It's not an error with the os module, the keys simply aren't in the enviroment. If you're using a .env file you should use a module like dotenv to load the file.

API Python smartsheet can't connect with SDK

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

Error using oauth2client in Python ServiceAccountCredentials has no attribute 'from_json_keyfile_name'

I have encountered a problem when using the oauth2client python library from google. Specifically in the following function
def getConnection(self):
scopes = ['https://www.googleapis.com/auth/sqlservice.admin']
crendialFilePath = ConfigHandler().getCredentialsFileName(self.credential_file_name)
print "crendialFilePath : " + crendialFilePath + "\n"
credentials = ServiceAccountCredentials.from_json_keyfile_name(crendialFilePath, scopes)
print "credentials : " + credentials + "\n"
return discovery.build('bigquery', 'v2', credentials=credentials)
I get the error:
AttributeError: type object 'ServiceAccountCredentials' has no attribute 'from_json_keyfile_name'
This code used to work and as best I can tell the only thing that has changed was over the weekend my computer was upgraded from WIndows 7 to 10.
Here is the full error from python
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Anaconda\lib\threading.py", line 810, in __bootstrap_inner
self.run()
File "C:\ABTests\BaseAnalysis.py", line 82, in run
bq = BQDB("DATASET_DOESNT_MATTER", dbName="bq_"+self.game_name)
File "C:\ABTests\RHIPythonUtils\Connectors\Database\bq.py", line 18, in __init__
self.connection = self.getConnection()
File "C:\ABTests\RHIPythonUtils\Connectors\Database\bq.py", line 53, in getConnection
credentials = ServiceAccountCredentials.from_json_keyfile_name(crendialFilePath, scopes)
AttributeError: type object 'ServiceAccountCredentials' has no attribute 'from_json_keyfile_name'
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Anaconda\lib\threading.py", line 810, in __bootstrap_inner
self.run()
File "C:\ABTests\BaseAnalysis.py", line 82, in run
bq = BQDB("DATASET_DOESNT_MATTER", dbName="bq_"+self.game_name)
File "C:\ABTests\RHIPythonUtils\Connectors\Database\bq.py", line 18, in __init__
self.connection = self.getConnection()
File "C:\ABTests\RHIPythonUtils\Connectors\Database\bq.py", line 53, in getConnection
credentials = ServiceAccountCredentials.from_json_keyfile_name(crendialFilePath, scopes)
AttributeError: type object 'ServiceAccountCredentials' has no attribute 'from_json_keyfile_name'
I am not the original author of this code, and unfortunately the person who is recently left.
I looked through the documentation for the ServiceAccountCredentials within the oauth2client content and it seems that from_json_keyfile_name is a legitimate function, but not an attribute. So I don't know why the error is saying it has no attribute for 'from_json_keyfile_name', unless that's a generic error for libraries when it can't find anything in that library/package that has a particular identifier.
My initial guess was that I needed to upgrade to the most recent version of the oauth2client, so I tried that and it didn't work.
I'd appreciate any help. If anyone has any suggestions, even about what would constitute minimally viable code, that would be great.
I wonder if it's possible that someone on the system's admin side has maybe done something with the service accounts? Does that seem like a plausible explanation?
What does your import look like? Ours is:
from oauth2client.service_account import ServiceAccountCredentials
That works like a charm.

How do I set the Engine used by ExecJS to NodeJS?

I'm trying to use the following package: https://github.com/Anorov/cloudflare-scrape/blob/master/cfscrape/init.py
I have the following test file:
import cfscrape
import sys
import execjs
who = sys.argv[1]
scraper = cfscrape.create_scraper()
print scraper.get(who).content
Which is outputting the following error:
Traceback (most recent call last): File "test.py", line 1, in import cfscrape File "build/bdist.macosx-10.10-intel/egg/cfscrape/__init__.py", line 17, in EnvironmentError: Your Javascript runtime 'JavaScriptCore' is not supported due to security concerns. Please use Node.js, V8, or PyV8.
Can anyone point me in the right direction to change my JS_ENGINE from JavaScriptCore to NodeJs

Categories

Resources