tensorflow_hub not working on google app engine - python-3.x

The following python code is throwing an error on Google App Engine:
import tensorflow_hub as hub
embed = hub.Module("https://tfhub.dev/google/universal-sentence-encoder/4")
Error:
RuntimeError: Missing implementation that supports: loader(*('/tmp/tfhub_modules/063d866c06683311b44b4992fd46003be952409c',), **{})
My app.yaml is Standard environment and is using
instance_class: F4_1G
This works on my local box

Seems like similar issue to the one posted here. Would you be able to confirm if this mitigation helped in your case?
The error message 'RuntimeError: Missing implementation ...' comes up when using a directory that exists but does not contain a tfhub_module.pb file with a known module format. In particular, you can get this message by trying to load a hub.Module from a directory that contains something else.

Related

AWS Lambda returns Unable to import module 'main': No module named 'main' when modules are there

So I'm trying to set up a function in AWS Lambda to run some python code I imported from a zip.
I've edited the handler to run the file then the function I want to run
I've tried having the file in the directory created when I imported the zip folder, after which I I moved it to the main function directory. Neither worked
Not too sure what is wrong here,
the full error returned when I run test is:
Response
{
"errorMessage": "Unable to import module 'main': No module named 'main'",
"errorType": "Runtime.ImportModuleError",
"stackTrace": []
}
Edit: really new to Lambda so please excuse any silly mistakes
The problem is that, while you appear to have a module named main, it has not been deployed to the Lambda service yet. When you click Test, Lambda runs the deployed code. Perhaps your module was renamed to main some time after your initial deployment?
Local changes to code need to be saved and then deployed. The deploy step is important because until you deploy the code, the Lambda service will continue to run the previous code.
This has actually been a common problem historically in the Lambda console, but enhancements have been made to make it more obvious that a deployment is needed. For example the console now indicates "Changes not deployed" after you make a change, until you hit the Deploy button.
I found this question while facing the problem myself. Issue was that the zip put "main.py" in a subfolder.
Hope this is helpful for any others!

Athenahealth Sandbox - No module named 'athenahealthapi'

I'm trying to play with sandbox on athenahealth - https://docs.athenahealth.com/api/guides/explore-and-prototype - After registering and creating an application, I begin using sandbox - try sandbox. I scroll to the sample code, go to GH >> samplecode >> python3 >> testing.py. When pulling this and running this code I continuously get error
ModuleNotFoundError: No module named 'athenahealthapi'
I am unable to install athenahealthapi
If you are looking at the API code samples you should see one that has a class connection called APIConnection. I believe you need to save that code as a file named athenahealthapi.py in the same folder that you are running your script. That essentially is the athenahealthapi module and it pulls the APIConnection class as athenahealthapi.APIConnection(). I got past that part but am now having trouble with a missing access_token key error. :(

Upload updated a file on Google Drive with Python using Drive API V3 does not work

I would not post this here but I invested hours now into understanding why the last part of my Python script does not behave as I expect it to behave reading documentation and many other posts on this topic.
What I want to achieve.
Create project in Google Cloud Platform and enable Drive API - works
Create OAuth credentials for Drive API - works
Authenticate with Google Drive from Python script - works
Download the file I want to edit with Python script - works
Upload the modified file after edit with Python script - does not work
I am using this function from the official Google documentation: https://developers.google.com/drive/api/v2/reference/files/update
But it gives the following error:
raise TypeError('Got an unexpected keyword argument "%s"' % name)
TypeError: Got an unexpected keyword argument "newRevision"
When I remove it from the function call I am getting this:
An error occurred:
<HttpError 403 when requesting https://www.googleapis.com/upload/drive/v3/files/1T1dl_Z3z-FDLa7lbWib8XxgbTd5pMpIP?alt=json&uploadType=resumable returned "The resource body includes fields which are not directly writable.">
I do not understand why I am getting this.
Why does the official sample contain a parameter that is not supported?
Is it possible that I am using a different version of the Google Python libraries locally then they expect me to have? I just followed the official documentation again?
Is is possible that I do not have sufficient rights to update the file?
Thanks,
Andre
Meanwhile I figured it out by myself why it was not working.
If you follow the Python Google Drive Quick Onboarding you will use version 3 of their API: https://developers.google.com/drive/api/v3/quickstart/python
This line defines the version:
service = build('drive', 'v3', credentials=creds)
If you continue searching in their documentation for a functionality to update a file I ended up here in the version 2 documentation and snippets:
https://developers.google.com/drive/api/v2/reference/files/update
Looking here for the version 3 snippet there is none existing in their documentation: https://developers.google.com/drive/api/v3/reference/files/update
So I assumed it is still valid what they posted for version 2, but this is not the case.
I did everything now in version 2 and it is finally working.
Edit to add reference:
newRevision is a valid parameter in v2, but not in v3, so I assume that, in v3, blob uploads always create a new revision (that's what happens in v2 if this parameter is not set – default is true). See Parameter differences between v2 and v3:
+--------------+--------------+--------------+
| Method | v2 Parameter | v3 Parameter |
+--------------+--------------+--------------+
| files.update | newRevision | n/a |
+--------------+--------------+--------------+

attempted relative import with no known parent package on Google AppEngine with Python3.7

Getting the following error:
"/srv/server.py", line 12, in from .routes.solver import route as solve ImportError: attempted relative import with no known parent package
Deploying the app to AppEngine Standard env, and my project looks like so:
---/
|_app.yaml
|_server.py
|_routes
|_solver.py
In server I do from .routes.solver import route as solve and get the above error in GCP, but not locally.
I tried https://stackoverflow.com/a/16985066/483616 and a few others. Tried with __init__.py at pretty much every level and every location. Then saw that it wasn't needed for python3, so removed. Pretty much unsure what to do now.
Not optimistic that this is the answer but just to throw it into the pot, have you seen Problem with Python relative paths when deploying to Google App Engine Flexible ?

Python2 connexion framework - controller in directory structure

I am playing around with using the connexion framework to setup a REST API access for my application.
My application is is built on python2, I installed the connexion framework for python2 and played around with the yaml file via the editor (editor.swagger.io). I downloaded the Python Flask server code, converted it to be compatable with Python2 and tested for a single controller.
When the controller is placed in the same directory as the place where the server is run. Everything was fine - all routes were added and working as expected. I then proceeded to split the controller based on some business logic and wanted a tree structure for each controller.
Something like
myapp/api/magic1/magic1_controller.py
myapp/api/magic2/magic2_controller.py
and so on.
This does not work for python2. It seems to work for python3. Any ideas why?
I get the following error from logs
DEBUG:connexion.api:Security Definitions: {}
DEBUG:connexion.api:Validate Responses: False
DEBUG:connexion.api:Creating API blueprint: /api
DEBUG:connexion.api:Adding swagger.json: /api/swagger.json
DEBUG:connexion.api:Adding swagger-ui: /api/ui/
DEBUG:connexion.api:Adding /api/magic1/{name}...
ERROR:connexion.api:Failed to add operation for GET /api/magic1/{name}
In the yaml config file I add the OperationId as api.magic1.func1() and so on.
Following the information you provided here the operationId should be set to api.magic1.magic1_controller.func1 and not api.magic1.magic1.func1().
You are missing to provide more details about your problem. Code snippets would help to guide you in a more detailed solution.

Resources