Google App Engine Devserver + dispatch.yaml (gcloud) - python

I am trying to start my app using the new cloud SDK preview (gcloud preview app run DIRNAME) and the response is:
INFO: Starting API server at: http://localhost:51695
INFO: Starting module "api" running at: http://localhost:8080
INFO: Starting module "default" running at: http://localhost:8081
INFO: Starting admin server at: http://localhost:8000
The dispatcher is not running and I can't get a dispatcher service URL as described
here.
The dispatcher is fully function on production, but I just can't get it started via dev server.
How can i make Google Cloud SDK recognize dispatch.yaml?
The dispatch.yaml looks like this:
application: my-super-secret-app-id
dispatch:
- url: "*/"
module: default
- url: "*/_*"
module: api
The goal is to server all "regular" requests from the default module, and request begins with underscore to the "api" module.

Removing Google Cloud SDK completely and re-installing it's latest version solved the problem.

Related

Deploying flask app on cpanel, INTERNAL SERVER ERROR when changing requesting other than base url

I want to deploy my flask-restx application on a shared hosting. Since I am beginner in deployment, I followed a video tutorial from youtube.
I did step by step by following this tutorial.
For those who do not want to go through the tutorial, I am writing the steps:
I created an application from the Python cPanel
Initial set up in Cpanel
Then I opened terminal and changed my venv and installed flask by "pip install flask"
Project Structure
filas_folder/
├──public
├──tmp
│ └──restart.txt
├──app.py
└──passenger_wsgi.py
app.py looks like
from flask import Flask
app = Flask(__name__)
#app.route("/")
def main_():
return "flask is running"
#app.route("/user")
def main_2():
return "user is running"
if __name__ == "__main__": app.run()
Restart app from cpanel
passenger.py looks like
import imp
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))
wsgi = imp.load_source('wsgi', 'app.py')
application = wsgi.app
when I open www.example.com
flask is running
But when I open www.example.com/user
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#example.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
My system has cloudlinux and uses apache server. This is not the first deployment. Many wordpress and static websites are running on the server.
I opened apache logs at /usr/local/apache/logs/error_log
I get the error "Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer" http://example.com/user"
Add the following to the top of your .htaccess file:
RewriteEngine on
RewriteRule ^http://%{HTTP_HOST}%{REQUEST_URI} [END,NE]
Got this info from: https://stackoverflow.com/a/63971427/10122266

How to Authenticate Google Cloud Services on PyGSheets deployed in Web Server (Heroku)

Hi I want to use pygsheets to log events to my google spreadsheet. This will be scheduled thus deployed in a web server particularly Heroku.
I am only using these lines to authenticate:
import pygsheets
gc = pygsheets.authorize()
Running locally, it works fine since I have to copy the authentication link and paste the code afterwards. But what if it's on Heroku.
I get these logs on Heroku:
2018-09-06T03:48:25.234859+00:00 app[web.1]: Your browser has been opened to visit:
2018-09-06T03:48:25.234861+00:00 app[web.1]:
2018-09-06T03:48:25.234870+00:00 app[web.1]: https://accounts.google.com/o/oauth2/auth?client_id=XXXXXXXX-iXXXXXXXXXXXXXX.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&response_type=code
2018-09-06T03:48:25.234872+00:00 app[web.1]:
I tried copying the link, it asked me to login. The endpoint was this link:
http://localhost:8080/?code=4/UgAXXXX6cdAt5Cnuj7yvTeoUgtfWyCvi8e2Rw-cxWiBVhACvom1qVgln0OfE1mOz3zENCXXXXvsOU4daXxI#
I am not sure why it is localhost.
I also research about authenticating Google Cloud Services for Heroku and bumped into this LINK.
I created another Service Account Key.
and wrote on my CLI:
$ heroku config:set GOOGLE_APPLICATION_CREDENTIALS=‘keyFile.json’
But it still doesn't solve the problem.
I still get these logs:
2018-09-06T03:55:59.083071+00:00 app[web.1]: Your browser has been opened to visit:
2018-09-06T03:55:59.083072+00:00 app[web.1]:
2018-09-06T03:55:59.083075+00:00 app[web.1]: https://accounts.google.com/o/oauth2/auth?client_id=XXXXX-isqd84kjnfu7o6XXXX6p79crvco2ms.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8090%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&response_type=code
2018-09-06T03:55:59.083076+00:00 app[web.1]:
2018-09-06T03:55:59.083078+00:00 app[web.1]: If your browser is on a different machine then exit and re-run this
2018-09-06T03:55:59.083080+00:00 app[web.1]: application with the command-line parameter
2018-09-06T03:55:59.083082+00:00 app[web.1]:
2018-09-06T03:55:59.083084+00:00 app[web.1]: --noauth_local_webserver
My directory BTW,
- app.py
- client_secret.json
- keyfile.json
- Procfile
- requirements.txt
More:
I also tried using:
gc = pygsheets.authorize(service_account_file='keyfile.json')
But the same output on Heroku.
I think your issue is you are using different version of pygsheets on your local and on Heroku. On your local you are using master version. but on the server you are using 1.1.4, which needs to set a outh_nonlocal param to enable oauthorization in server. also the param for the service_account was changed from service_file.

Cannot import subprocess.call when running google app engine locally

I am beginning to test google app engine for running my flask app. I can run the app directly using flask run without a problem. My app.yaml looks like this
runtime: python27
api_version: 1
threadsafe: true
# [START handlers]
handlers:
- url: /static
static_dir: CameraMeerat/static
- url: /.*
script: CameraMeerkat.app
# [END handlers]
When running dev_appserver.py I get
File "C:\Users\Ben\Documents\CameraMeerkat\Frontend\CameraMeerkat\commands.py", line 5, in <module>
from subprocess import call
ImportError: cannot import name call
INFO 2017-07-21 21:26:37,585 module.py:813] default: "GET / HTTP/1.1" 500 -
From my python shell I can run that command
from subprocess import call
help(call)
Help on function call in module subprocess:
call(*popenargs, **kwargs)
Run command with arguments. Wait for command to complete, then
return the returncode attribute.
The arguments are the same as for the Popen constructor. Example:
retcode = call(["ls", "-l"])
What might be going on here? Subprocess is not a module that can be installed, or really messed with. Similar to unanswered here
ImportError: cannot import name Popen google cloud compute delpoyment error ?
This is one of the limitation imposed by the GAE standard environment Python sandbox. From The sandbox (emphasis mine):
An App Engine application cannot:
write to the filesystem. Applications must use Cloud Datastore for storing persistent data. Reading from the filesystem is allowed, and
all application files uploaded with the application are available.
respond slowly. A web request to an application must be handled within a few seconds. Processes that take a very long time to respond
are terminated to avoid overloading the web server.
make other kinds of system calls.
One of the disallowed system calls is subprocess.call. The development server will raise an exception as it contains a modified version of subprocess.
If your app requires such call you may need to switch to the flexible enviroment. See also Choosing your App Engine environment

apprtc - getusermedia() failed

i downloaded apprtc from here. Then i installed python 2.7, the google-appengine-api and all dependencies. i add all to my path and run the following command:
dev_appserver.py apprtc
which produce the following output:
INFO 2014-04-24 21:31:34,246 sdk_update_checker.py:242] Checking for updates
to the SDK.
INFO 2014-04-24 21:31:35,681 sdk_update_checker.py:286] This SDK release is
newer than the advertised release.
INFO 2014-04-24 21:31:35,917 api_server.py:171] Starting API server at: http
://localhost:46857
INFO 2014-04-24 21:31:35,924 dispatcher.py:182] Starting module "default" ru
nning at: http://localhost:8080
INFO 2014-04-24 21:31:35,927 admin_server.py:117] Starting admin server at:
http://localhost:8000
but if i now open localhost:8080 in chrome or firefox there popup the following message:
getusermedia() failed. is this a webrtc capable browser
Gathered ICE Candidates
Local:
Remote:
getUserMedia failed with exception: getUserMedia is not defined
but if i open the official apprtc demo it's running fine.
what can be the reason for the failures i get local?
thank you!
try this to getuser media
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;

AssertionError: No api proxy found for service "xmpp"

I am trying to run gae app without dev_appserver.py, and have following error
AssertionError: No api proxy found for service "xmpp"
room = webrtc.Room.get_by_key_name(room_key)
I found in the app.yaml inbound_services:
- channel_presence
How to enable channel_presence directly in application.py
Unless otherwise specified, libraries included with the App Engine SDK are expected only to work within the App Engine environment. You cannot just import the XMPP library included with the App Engine SDK and expect it to work in a non-GAE application.

Categories