getUser return EDAMSystemException errorCode=8 - python

I'm trying to get my account information by evernote api on python, however, I got errors :
Traceback (most recent call last): File "", line 1, in
File "build/bdist.linux-x86_64/egg/evernote/api/client.py", line 148, in delegate_method
File "build/bdist.linux-x86_64/egg/evernote/edam/userstore/UserStore.py", line 1033, in getUser
File "build/bdist.linux-x86_64/egg/evernote/edam/userstore/UserStore.py", line 1058, in recv_getUser
evernote.edam.error.ttypes.EDAMSystemException: EDAMSystemException(errorCode=8, rateLimitDuration=None, _message='authenticationToken')
My python code as below:
from evernote.api.client import EvernoteClient
dev_token="my develop token"
client = EvernoteClient(token=dev_token)
userStore = client.get_user_store()
user = userStore.getUser()
I'm sure I've generated a valid developer token for my Evernote account, as shown in the picture, I have a develop token in my account link
Is there anything I missed?
By the way, I use the code above and replace the key with another develop token generated by Evernote sandbox account, it's ok.

If you are not on sandbox, try:
client = EvernoteClient(token=dev_token, sandbox=False)

Related

how to use offical google translate api on local runtime via python

after reading the offical google translate api document, it provide us with the following sample code:
from google.cloud import translate
def translate_text(text="Hello, world!", project_id="weighty-site-333613"):
client = translate.TranslationServiceClient().from_service_account_json('key.json')
location = "global"
parent = f"projects/{project_id}/locations/{location}"
response = client.translate_text(
request={
"parent": parent,
"contents": [text],
"mime_type": "text/plain",
"source_language_code": "en-US",
"target_language_code": "zh-CN",
}
)
for translation in response.translations:
print("Translated text: {}".format(translation.translated_text))
translate_text()
These code worked properly on google cloud terminal.
However, even if i put the "key.json" file in the same folder, an error like this is shown:
/usr/local/bin/python3.6 /Users/jiajunmao/Documents/GitHub/translator_of_excel/google_trans.py
Traceback (most recent call last):
File "/Users/jiajunmao/Documents/GitHub/translator_of_excel/google_trans.py", line 37, in <module>
translate_text()
File "/Users/jiajunmao/Documents/GitHub/translator_of_excel/google_trans.py", line 22, in translate_text
client = translate.TranslationServiceClient().from_service_account_json('key.json')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/translate_v3/services/translation_service/client.py", line 354, in __init__
always_use_jwt_access=True,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/translate_v3/services/translation_service/transports/grpc.py", line 158, in __init__
always_use_jwt_access=always_use_jwt_access,
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/cloud/translate_v3/services/translation_service/transports/base.py", line 110, in __init__
**scopes_kwargs, quota_project_id=quota_project_id
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/google/auth/_default.py", line 488, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
Process finished with exit code 1
can someone tell me what should i do at this step? thank you so much
You need service account json file with correct permissions from GCP under IAM & Service Accounts.
Then you need to implement command,
GOOGLE_APPLICATION_CREDENTIALS = "/path/to/your/service_account.json"

Instagram API access token generation throws "You must provide a client_id" error even though I provided one

Generating an access token for the Python Instagram API requires running this file and then entering a Client ID, Client Secret, Redirect URI, and Scope. The console then outputs a URL to follow to authorize the app and asks for the code generated afterwards. Theoretically after this process it should return an access token.
Instead, it's throwing an error:
Traceback (most recent call last):
File "get_access_token.py", line 40, in <module>
access_token = api.exchange_code_for_access_token(code)
File "C:\Users\Daniel Leybzon\Anaconda2\lib\site-packages\instagram\oauth2.py", line 48, in exchange_code_for_access_token
return req.exchange_for_access_token(code=code)
File "C:\Users\Daniel Leybzon\Anaconda2\lib\site-packages\instagram\oauth2.py", line 115, in exchange_for_access_token
raise OAuth2AuthExchangeError(parsed_content.get("error_message", ""))
instagram.oauth2.OAuth2AuthExchangeError: You must provide a client_id
Screenshot provided for context:

Instagram API Python error

I'm trying to familiarize with the library python-instagram.
I've done this code:
from instagram.client import InstagramAPI
clientid = '***'
clientsecret = '***'
api = InstagramAPI(client_id=clientid, client_secret=clientsecret)
tag_name = raw_input("Write the word that you want")
filtered_media = api.tag_recent_media(count=20, max_id=1, tag_name=tag_name)
for media in filtered_media:
print media.images['standard_resolution'].url
and I get the following error using the command line (I have a mac):
Traceback (most recent call last):
File "test.py", line 7, in <module>
filtered_media = api.tag_recent_media(count=20, max_id=1, tag_name=tag_name)
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 197, in _call
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 189, in execute
File "build/bdist.macosx-10.6-intel/egg/instagram/bind.py", line 163, in _do_api_request
instagram.bind.InstagramAPIError: (400) OAuthAccessTokenException-The access_token provided is invalid.
Someone knows what is happen? THANKS
I would suggest you to take a look at this sample app . You will get to know how to use python-instagram library.
In your code , You are passing client Id in InstagramAPI(). But as per their sample app required argument is access_token.
code snippet from sample_app.py
api = client.InstagramAPI(access_token=access_token, client_secret=CONFIG['client_secret'])
tag_search, next_tag = api.tag_search(q="backclimateaction")
tag_recent_media, next = api.tag_recent_media(tag_name=tag_search[0].name)
To get tag_search result you must have access_token. you can read this documentation to learn how to generate access token from your app.

Twilio - Python : NameError from Udacity Tutorial

Hoping I could get input on what this error means and what I have to do to fix it. Thanks.
This is the error that appears:
Traceback (most recent call last):
File "/Users/davidongchoco/Desktop/Python Programming/send_text.py", line 11, in <module>
from_="+13348331130") # Replace with your Twilio number
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/sms_messages.py", line 167, in create
return self.create_instance(kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 365, in create_instance
data=transform_params(body))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 200, in request
resp = make_twilio_request(method, uri, auth=self.auth, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twilio/rest/resources/base.py", line 164, in make_twilio_request
uri=resp.url, msg=message, code=code)
TwilioRestException:
[31m[49mHTTP Error[0m [37m[49mYour request was:[0m
[36m[49mPOST https://api.twilio.com/2010-04-01/Accounts/ACf37c4004688accd3f501ab2a2c9dc7e1/SMS/Messages.json[0m
[37m[49mTwilio returned the following information:[0m
[34m[49mPermission to send an SMS has not been enabled for the region indicated by the 'To' number: +639228902063.[0m
[37m[49mMore information may be available here:[0m
[34m[49mhttps://www.twilio.com/docs/errors/21408[0m
>>>
Twilio developer evangelist here.
The error has delivered a message to you that says:
Permission to send an SMS has not been enabled for the region indicated by the 'To' number: +639228902063.
More information may be available here:
https://www.twilio.com/docs/errors/21408
If you follow that link, it tells you that you need to enable some global permissions on your account. You can do that here: https://www.twilio.com/user/account/settings/international/sms
It looks as though you are trying to send to a number from the Philippines, so make sure that check box is ticked.
Good luck with the Udacity course!

Unable to upgrade YouTube session token without logging into Google Accounts user API

I am having trouble upgrading my session token in google app engine if my user is not logged into my application using the google accounts user api. If the user is currently logged in then it functions perfectly.
If not then i am getting this error:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 511, in __call__
handler.get(*groups)
File "/base/data/home/apps/5th-anniversary/1.341853888797531127/main.py", line 78, in get
u.upgradeToken(self)
File "/base/data/home/apps/5th-anniversary/1.341853888797531127/upload.py", line 47, in upgradeToken
client.UpgradeToSessionToken()
File "/base/data/home/apps/5th-anniversary/1.341853888797531127/gdata/service.py", line 903, in UpgradeToSessionToken
raise NonAuthSubToken
NonAuthSubToken
What are my best options here? I do not want the user to have to log into the google accounts api and then the youtube site to upload a video.
here is my method for updating the token:
def upgradeToken(data,self):
get = self.request.GET
authsub_token = get['token']
gdata.alt.appengine.run_on_appengine(client)
client.SetAuthSubToken(authsub_token)
client.UpgradeToSessionToken()
client is simply client = gdata.youtube.service.YouTubeService()
pretty sure i'm missing something on the authentication side but i can't seem to see what, thanks!
I solved this by using:
client.UpgradeToSessionToken(gdata.auth.extract_auth_sub_token_from_url(self.request.url))
but this raised another issue when building the upload form with
GetFormUploadToken
i receive:
Traceback (most recent call last):
File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__
handler.post(*groups)
File "/base/data/home/apps/5th-anniversary/1.341859541699944556/upload.py", line 106, in post
form = u.getUploadForm(self,title,description,keywords)
File "/base/data/home/apps/5th-anniversary/1.341859541699944556/upload.py", line 65, in getUploadForm
response = client.GetFormUploadToken(video_entry,'http://gdata.youtube.com/action/GetUploadToken')
File "/base/data/home/apps/5th-anniversary/1.341859541699944556/gdata/youtube/service.py", line 716, in GetFormUploadToken
raise YouTubeError(e.args[0])
YouTubeError: {'status': 401L, 'body': '<HTML>\n<HEAD>\n<TITLE>User authentication required.</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>User authentication required.</H1>\n<H2>Error 401</H2>\n</BODY>\n</HTML>\n', 'reason': ''}
Try this:
new_token = client.UpgradeToOAuthAccessToken(
gdata.auth.extract_auth_sub_token_from_url(self.request.url)
client.SetOAuthToken(new_token)
client.GetFormUploadToken(my_video_entry)

Categories