IOError: [Errno 13] file not accessible GAE - python

I want to access a file in my computer from a google app engine application. If I put the file in the src folder of the application there is no problem but I need this file to be out of that folder.
When I try to access this file I get the next error:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py", line 712, in __call__
handler.post(*groups)
File "C:\Users\path\Documents\path\oauth2client\appengine.py", line 469, in check_oauth
return method(request_handler, *args, **kwargs)
File "C:\Users\path\Documents\path\myapp.py", line 88, in post
filename=open('C:/Users/path_to_file/Documento 1.docx','r')
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver_import_hook.py", line 635, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: 'C:/Users/path_to_file/Documento 1.docx'
I have read that if a file is defined as static in app.yaml can't be accessible from GAE. This is my app.yaml. I can't figure out if there is something wrong:
application: myapp
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: myapp.py
And this is the part of the application that tries to access the file:
filename='C:/Users/path_to_file/Documento 1.docx'
media_body = MediaFileUpload(filename,resumable=True)
Does someone know why do I get the "file not accessible" error?
Thanks!

Put the file in the same directory as the rest of your applications files (i.e. where the app.yaml is).
All the files you want your application to access have to be in the same place, under your main application directory.
GAE can't access arbitrary files somewhere on your computer, just like it cannot access files saved "somewhere" else when deployed.
filename='myfile.doc'
That's assuming it's in the 'root' (same as app.yaml).

In your app.yaml file you need to make the file visible to your app:
handlers:
- url: /<location to your data files>
script: <your app name>.app
For example in my app.yaml file it looks like this
- url: /data
script: main.app

Related

Django,IIS. I can't publish django using IIS

I'm trying to publish django using Microsoft IIS. I got an error when accessing http://localhost. Django version is 3.1.7 and python is 3.9.2, windows server 2019.
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "c:\program files\python39\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "c:\program files\python39\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "c:\program files\python39\lib\site-packages\wfastcgi.py", line 603, in get_wsgi_handler
handler = getattr(handler, name)
AttributeError: module 'django.core' has no attribute 'wsgi'
StdOut:
StdErr:
There are many reasons for this error, you can try below methods to solve this error:
In your Django project, there is a init.py file, remove it and try again.
Try to find your Python folder (C:\python27 by default) and forcibly reset the permissions, i.e. Replace all child object permissions with inheritable permissions from this object as shown here: https://serverfault.com/questions/475612/replace-permission-entries-on-all-child-objects-using-icacls
If the problem cannot be solved, please share your project path and Web.config file.

Flask import is failing in standard environment of Google App Engine

I have specified an app.yaml file as follows:
runtime: python
env: standard
# this assumes that the entrypoint is app.py
entrypoint: gunicorn -b :$PORT main:app
threadsafe: true
After running gcloud app deploy I'm faced with a 500 error and the logs reveal the following
Traceback (most recent call last):
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27_experiment/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/g~test-website/20170924t080410.404328292497306090/app.py", line 3, in <module>
from flask import Flask, render_template
ImportError: No module named flask
Can anyone help me configure a standard environment
You are combining syntax for the flexible environment and the standard environment in your app.yaml
Look at the documentation for the app.yaml and stick to the standard environment reference. The env parameter is only used for flex and entrypoint is only for flex. The runtime parameter should be python27 as python means the deprecated Python 2.5 runtime.
Given that you're trying to use Flask, you should probably read the getting started guide that is specifically for Flask.

Adding Google Analytics API Library to Google App Engine

I am trying to run a simple python script on Google App Engine. How do I install the Google Analytics API library?
Library: https://developers.google.com/api-client-library/python/apis/analytics/v3
Instructions: https://cloud.google.com/appengine/docs/python/tools/libraries27#vendoring
I've tried everything and can't get this to run, even though it works on my pc. What I have right now is:
The python scripts in the root folder,
In the /lib folder I copied the folders that were installed from my PC (/googleapiclient and /google_api_python_client-1.4.0-py2.7.egg-info)
And I have appengine_config.py in /lib folder which contains:
from google.appengine.ext import vendor
# Add any libraries installed in the "lib" folder.
vendor.add('lib')
vendor.add('google-api-client')
app.yaml file:
application: psyched-cab-861
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: hello_analytics_api_v3.app
Traceback:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
ImportError: No module named helloworld
New Log:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 354, in __getattr__
self._update_configs()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 290, in _update_configs
self._registry.initialize()
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/base/data/home/apps/s~just-terminus-94303/1.384249106864280829/appengine_config.py", line 5, in <module>
vendor.add('google-api-python-client')
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/ext/vendor/__init__.py", line 44, in add
'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access google-api-python-client: No such virtualenv or site directory
I tried editing the appengine_config.py file to
vendor.add('googleapiclient') #The name of the file
I edit it in GAE, and click commit, it saves, but I get the same error as above with the vendor.add('google-api-python-client') error. Why is the file not updating?
As the docs say: put the appengine_config.py in your root folder of the application (and not in the /lib folder).
By the way, the name of the library is google-api-python-client and not google-api-client.
Then you have to install google-python-api-client in your /lib folder:
$ pip install -t lib google-api-python-client

How to run two versions of an application using Google App Engine dev server with Python

I am using Ubuntu Server 13.10 and Python 2.7.
I would like to have two versions of my App Engine application: admin and the default version. I have defined these two versions. Currently, this is my app.yaml file:
application: application-id
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /
script: python.MainPage.application
- url: /test.*
script: gaeunit.application
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
version: admin
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /css
static_dir: css
- url: /js
static_dir: js
- url: /.*
script: python.MainPage.application
login: admin
auth_fail_action: unauthorized
- url: /test.*
script: python.MainPage.appication
libraries:
- name: webapp2
version: latest
- name: jinja2
version: latest
When I deploy this code to App Engine, it works as expected. However, If I attempt to run it using dev_appserver.py found in the Google Cloud SDK, it fails with this traceback:
Traceback (most recent call last):
File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 82, in <module>
_run_file(__file__, globals())
File "/home/katie/google-cloud-sdk/platform/google_appengine/dev_appserver.py", line 78, in _run_file
execfile(_PATHS.script_file(script_name), globals_)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 902, in <module>
main()
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 895, in main
dev_server.start(options)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/devappserver2.py", line 672, in start
options.yaml_files)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 556, in __init__
module_configuration = ModuleConfiguration(yaml_path)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 82, in __init__
self._yaml_path)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/application_configuration.py", line 272, in _parse_configuration
return appinfo_includes.ParseAndReturnIncludePaths(f)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo_includes.py", line 63, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/appinfo.py", line 1826, in LoadSingleAppInfo
listener.Parse(app_info)
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 226, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "/home/katie/google-cloud-sdk/platform/google_appengine/google/appengine/api/yaml_listener.py", line 177, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: Duplicate attribute 'version'.
in "aerobic-arcade-514/default/app.yaml", line 24, column 10
You can launch two different dev app servers on two different ports, just override the default port with the --port= parameter, however you will need to have two app.yaml files separated, not using the same file as you did. When you run dev_appserver.py, use the config file as the final argument instead of the directory (which defaults to app.yaml).
For example:
dev_appserver.py --port=8888 app_one.yaml
dev_appserver.py --port=9999 app_two.yaml
After your testing and before deploying, make sure you leave the definitive file with the name app.yaml; otherwise, you won't be able to complete the process.

Cannot run Hello World on Google App Engine Windows

I have downaloded and installed Python 2.7.6 in my Windows and I have also installed the latest version of the GAE SDK for Windows as well.
I have the following configurations on my GAE:
I am running an Hello World project with the following files:
Main.py
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello world!')
app = webapp2.WSGIApplication([('/', MainHandler)], debug=True)
app.yaml
application: HelloWorld
version: 1
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
However, When I click the button Run, in order to runt he project, I get the following errors in the LOG output:
2013-12-04 14:51:49 Running command: "['C:\\Python27\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--skip_sdk_update_check=yes', '--port=8080', '--admin_port=8000', 'D:\\Users\\pedro\\Desktop\\HelloWorld']"
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 197, in <module>
_run_file(__file__, globals())
File "C:\Program Files (x86)\Google\google_appengine\dev_appserver.py", line 193, in _run_file
execfile(script_path, globals_)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 872, in <module>
main()
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 865, in main
dev_server.start(options)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\devappserver2.py", line 657, in start
options.yaml_files)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 549, in __init__
module_configuration = ModuleConfiguration(yaml_path)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 82, in __init__
self._yaml_path)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\application_configuration.py", line 266, in _parse_configuration
return appinfo_includes.ParseAndReturnIncludePaths(f)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\appinfo_includes.py", line 63, in ParseAndReturnIncludePaths
appyaml = appinfo.LoadSingleAppInfo(appinfo_file)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\appinfo.py", line 1756, in LoadSingleAppInfo
listener.Parse(app_info)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\yaml_listener.py", line 226, in Parse
self._HandleEvents(self._GenerateEventParameters(stream, loader_class))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\api\yaml_listener.py", line 177, in _HandleEvents
raise yaml_errors.EventError(e, event_object)
google.appengine.api.yaml_errors.EventError: Unable to assign value 'HelloWorld' to attribute 'application':
Value 'HelloWorld' for application does not match expression '^(?:(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{0,99}[a-z\d])$'
in "D:\Users\pedro\Desktop\HelloWorld\app.yaml", line 1, column 14
2013-12-04 14:51:50 (Process exited with code 1)
Thus I have the following questoins:
I have created this project by going to File -> New application, but apparently my auto-generated app.yaml file is incorrect. What am I doing wrong?
I have tried to use Python 3.3 first, but it was not working. GAE only works with Python 2.7 right? I am doing everythign correctly right?
When I click the Browse button I get the error saying that no browser is specified. How do I fix that?
Thanks for any help if possible :S
According to the regex that isn't matching, the app name needs to be lowercase:
>>> regex = r'^(?:(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{0,99}[a-z\d])$'
>>> print(re.match(regex, 'HelloWorld'))
None
>>> print(re.match(regex, 'helloworld'))
<_sre.SRE_Match object at 0x13ac308>
Your application identifier('HelloWorld') is invalid. You should use the one you created in the Administration Console according to the GAE doc.
The ID will be the subdomain of your GAE application when it deployed in appspot.com. That's why the app id should match the regex r'^(?:(?:[a-z\d\-]{1,100}\~)?(?:(?!\-)[a-z\d\-\.]{1,100}:)?(?!-)[a-z\d\-]{0,99}[a-z\d])$'.

Categories

Resources