Error getting started with cloud endpoints on GAE - python

I'm just getting started with cloud endpoints by following the tutorial from
here.
Even when i copy paste the code exactly, I'm unable to look at the custom endpoin methods. When I run the project and type
http://localhost:8080/_ah/api/explorer
I get redirected to a blank api-explorer page. Here are the logs from the App Engine Launcher
INFO 2015-09-22 20:45:52,114 devappserver2.py:763] Skipping SDK update check.
INFO 2015-09-22 20:45:52,661 api_server.py:205] Starting API server at: http://localhost:53371
INFO 2015-09-22 20:45:52,676 dispatcher.py:197] Starting module "default" running at: http://localhost:8080`
INFO 2015-09-22 20:45:52,676 admin_server.py:118] Starting admin server at: http://localhost:8000
INFO 2015-09-22 20:46:08,792 module.py:808] default: "GET /_ah/api/explorer HTTP/1.1" 302 -
INFO 2015-09-22 20:46:12,805 module.py:808] default: "GET /_ah/api/explorer HTTP/1.1" 302 -
INFO 2015-09-22 20:46:17,711 module.py:808] default: "GET /_ah/api/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.z0-pPDgHPQw.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCO4-ZDXf1JrE4AXDItAeFdjXKLW8w HTTP/1.1" 200 7690
The app.yaml and python files are exactly as described in the tutorial.
Can someone please tell me what exactly is going on and how to fix it.

Related

Flasgger: Swagger App - http://127.0.0.1:5000/apidocs/ - Fetch errorINTERNAL SERVER ERROR /apispec_1.json

I created a Flasgger/Swagger App in Spyder and got returned:
127.0.0.1 - - [28/Mar/2021 21:49:13] "GET /apispec_1.json HTTP/1.1" 500 -
127.0.0.1 - - [28/Mar/2021 21:49:13] "GET /flasgger_static/favicon-32x32.png HTTP/1.1" 200 -
When trying to visit this app in my Google Chrome browser via http://127.0.0.1:5000/apidocs/ I got back this error:
Fetch error
INTERNAL SERVER ERROR /apispec_1.json
What do I have to change here?

Django Unexpected 405 Response

Problem
My django application often respond 405 Method Now Allowed even though
it's working api on development environment. But if i restart
development server (python manage.py runserver) It works.
Environment
macOS Mojave 10.14
Python 3.6.4 (Isolated environment via Pipenv)
Django 2.1.4
djangorestframework 3.8.2
API Code
settings/urls.py (root url file)
from django.urls import path, include
import my_account.urls
urlpatterns = [
path('account/', include(my_account.urls, namespace='account_v1')),
]
my_account/urls.py
from django.urls import path
from .apps import MyAccountConfig
from .views import TokenView
app_name = MyAccountConfig.name
urlpatterns = [
path('token/', TokenView.as_view()),
]
my_account/views.py
from rest_framework.views import APIView
class TokenView(APIView):
def post(self, request):
# Some Business-Logic Code
pass
Log
Log when 405 occured
System check identified no issues (0 silenced).
December 07, 2018 - 11:22:54
Django version 2.1.4, using settings 'my_server.settings.staging'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
.env Applied
[07/Dec/2018 11:24:30] "OPTIONS /account/token/ HTTP/1.1" 200 0
[07/Dec/2018 11:24:30] "{"email":"email#hidden.com","password":"hidden_password"}POST /account/token/ HTTP/1.1" 405 66
Log when working
System check identified no issues (0 silenced).
December 07, 2018 - 11:48:01
Django version 2.1.4, using settings 'my_server.settings.staging'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
.env Applied
[07/Dec/2018 11:48:08] "OPTIONS /account/token/ HTTP/1.1" 200 0
[07/Dec/2018 11:48:09] "POST /account/token/ HTTP/1.1" 200 517
In chrome network tab, no difference between request for 200 and 405.
I Have faced this same error for the last two months eventually I Solved at the end.
Error:
When a user token is become expired we will be getting 401 status code with unauthorized message, when this happens the next API is also getting interrupted it returns 405 Method Not Allowed as an error.
Solution :
There was a bug issue in Django version 2.1 you have to upgrade your django version to 2.2.
After that check this error it will not raise.
HTTP_405_METHOD_NOT_ALLOWED
The status code 405 represents that you are requesting in a method that is not allowed.
Based on your code, You are defining Token API to be accessible by post method.
look at this log:
[07/Dec/2018 11:48:09] "POST /account/token/ HTTP/1.1" 200 517
in this you are sending clear POST request which will be ok. but look at the provided log for failed cases:
[07/Dec/2018 11:24:30] "{"email":"email#hidden.com","password":"hidden_password"}POST /v1/account/token/ HTTP/1.1" 405 66
1- For some reason in your UI, you are sending a request with method {"email":"email#hidden.com","password":"hidden_password"}POST!!!!.
2- and you are sending request to /v1/account/token/ API endpoint which is not registered in your urls at all (based on what info you gave us)

Rudimentary caching not working in a Google App Engine application

I'm making a blog using Google App Engine, which for now just allows me to post entries and see them listed out. I was following the Web Development course by Steve Huffman on Udacity where he showed a simple caching technique to decrease the database queries. Here's my code (which he instructed):
CACHE = {}
def top_entries():
key = 'top'
# logging.error(CACHE)
if key in CACHE:
entries = CACHE[key]
else:
logging.error("DB QUERY")
entries = db.GqlQuery('select * from Entries order by created desc limit 10')
entries = list(entries)
CACHE[key] = entries
return entries
class MainPage(webapp2.RequestHandler):
def get(self):
entries = top_entries()
self.response.write(render_str('mainpage.html', entries=entries))
mainpage.html is just the main page that lists the 10 most recent entries.
Basically, CACHE is a dictionary that stores a key that identifies a particular database query (in this case, listing out the top 10 entries) and on further calls to the same query, the application simply looks in that dictionary without making a database call.
What SHOULD happen is this:
I load the page for the first time and DB QUERY is printed on my console since it's a database call. The result of the query is stored in CACHE.
I reload and DB QUERY isn't printed since the cache has the key.
The above DOES happen but only if I have a fresh new tab to work on. If I already have a tab where I was working on this app, and I shut down the server, reboot it and then try reloading the page again, the above doesn't work. What happens is that step 1 happens twice and then step 2. It seems like the key isn't stored in the CACHE the first time I reload the page, but on the second time.
Here's the console log if the above paragraph is hard to follow:
The first time I boot the server and start working on a fresh tab:
PS C:\Users\IBM_ADMIN> python `C:\Program Files (x86)\Google\google_appengine\dev_appserver.py' 'C:\Users\IBM_ADMIN\Downloads\Udacity\Web Development\Blog Project'
INFO 2016-06-16 14:31:04,000 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO 2016-06-16 14:31:06,525 api_server.py:205] Starting API server at: http://localhost:53305
INFO 2016-06-16 14:31:06,545 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-06-16 14:31:06,552 admin_server.py:116] Starting admin server at: http://localhost:8000
ERROR 2016-06-16 09:01:15,358 blog.py:134] DB QUERY
INFO 2016-06-16 14:31:15,529 module.py:787] default: "GET / HTTP/1.1" 200 1849
INFO 2016-06-16 14:31:17,984 module.py:787] default: "GET / HTTP/1.1" 200 1849
INFO 2016-06-16 14:31:45,944 shutdown.py:45] Shutting down.
INFO 2016-06-16 14:31:46,040 api_server.py:648] Applying all pending transactions and saving the datastore
INFO 2016-06-16 14:31:46,042 api_server.py:651] Saving search indexes
And this is what happens when I don't open a fresh tab but start working on the old tab.
PS C:\Users\IBM_ADMIN> python `C:\Program Files (x86)\Google\google_appengine\dev_appserver.py' 'C:\Users\IBM_ADMIN\Downloads\Udacity\Web Development\Blog Project'
INFO 2016-06-16 14:31:56,470 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO 2016-06-16 14:31:58,637 api_server.py:205] Starting API server at: http://localhost:53318
INFO 2016-06-16 14:31:58,651 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-06-16 14:31:58,657 admin_server.py:116] Starting admin server at: http://localhost:8000
ERROR 2016-06-16 09:02:08,336 blog.py:134] DB QUERY
INFO 2016-06-16 14:32:08,526 module.py:787] default: "GET / HTTP/1.1" 200 1849
ERROR 2016-06-16 09:02:12,538 blog.py:134] DB QUERY
INFO 2016-06-16 14:32:12,684 module.py:787] default: "GET / HTTP/1.1" 200 1849
INFO 2016-06-16 14:32:16,822 module.py:787] default: "GET / HTTP/1.1" 200 1849
INFO 2016-06-16 14:32:21,428 shutdown.py:45] Shutting down.
INFO 2016-06-16 14:32:21,430 api_server.py:648] Applying all pending transactions and saving the datastore
INFO 2016-06-16 14:32:21,430 api_server.py:651] Saving search indexes
DB QUERY gets printed out twice instead of once. I can't think of any reason why it would behave this way. (Maybe because of my browser cookies?)
You are caching at instance level and you can have number of instances or an instance can be recycled (shut down) and a new one instantiated on a request.
Try to use Memcache if you want to share cache between instances:
https://cloud.google.com/appengine/docs/python/memcache/
You can combine both approaches (instance cache + memcache)

Form not appearing using Django/HTML/Python [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am new to Django and web development. I don't know how to describe my problem. No idea what info to provide. I need some hints to debug.
I have two virtual machines. On one machine, I built my Django project, installed the package, and run it on apache2.
On the other machine, I run python manage.py runserver 0.0.0.0:8000 from the source codes.
Browsing the same page, the web page on machine 1 is OK.
But nearly every form disappeared on machine 2.
Checked the source of the two pages, they are the same.
The output on machine 2 seems OK too:
[17/Mar/2016 19:36:40] "GET /myapp/dashboard/reports/new HTTP/1.1" 302 0
[17/Mar/2016 19:36:40] "GET /myapp/dashboard/reports/0 HTTP/1.1" 200 43321
[17/Mar/2016 19:36:40] "GET /myapp/static/dist/css/vendor.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/main.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/dashboard.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/query.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/css/report.css?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/dist/js/commons.bundle.js?v=v1.71 HTTP/1.1" 304 0
[17/Mar/2016 19:36:40] "GET /myapp/static/dist/js/analytics.bundle.js?v=v1.71 HTTP/1.1" 304 0
UPDATE
ERROR:
Uncaught TypeError: $(...).daterangepicker is not a functiont.exports.n.View.extend.initialize # analytics.bundle.js?v=v1.71:2e.View # commons.bundle.js?v=v1.71:56n # commons.bundle.js?v=v1.71:56t.exports.n.View.extend.initialize # analytics.bundle.js?v=v1.71:1e.View # commons.bundle.js?v=v1.71:56n # commons.bundle.js?v=v1.71:56(anonymous function) # analytics.bundle.js?v=v1.71:1c # commons.bundle.js?v=v1.71:24h.fireWith # commons.bundle.js?v=v1.71:24vt.extend.ready # commons.bundle.js?v=v1.71:24h # commons.bundle.js?v=v1.71:14
UPDATE
Solved this problem. see the error above. It failed to import some js files, and then the page not shown.
If they're each using separate copies of the database server, it may be that database migrations have not been run yet on machine 2.

Periodic Django Logs in Terminal

I am new to Django and this question may seem to be easy. In the terminal where "python manage.py runserver" is executed, the following logs periodically appear.
[30/Sep/2015 02:36:02] "GET /messages/check/?_=1443574208652 HTTP/1.1" 200 1
[30/Sep/2015 02:36:08] "GET /notifications/check/?_=1443574208653 HTTP/1.1" 200 1
[30/Sep/2015 02:36:08] "GET /feeds/update/?first_feed=13&last_feed=6&feed_source=all&_=1443574208655 HTTP/1.1" 200 173
[30/Sep/2015 02:36:08] "GET /feeds/check/?last_feed=13&feed_source=all&_=1443574208654 HTTP/1.1" 200 1
[30/Sep/2015 02:36:39] "GET /notifications/check/?_=1443574208656 HTTP/1.1" 200 1
[30/Sep/2015 02:36:39] "GET /feeds/check/?last_feed=13&feed_source=all&_=1443574208658 HTTP/1.1" 200 1
[30/Sep/2015 02:36:39] "GET /feeds/update/?first_feed=13&last_feed=6&feed_source=all&_=1443574208657 HTTP/1.1" 200 173
[30/Sep/2015 02:37:03] "GET /messages/check/?_=1443574208659 HTTP/1.1" 200 1
My Django virtual environment is as follows:
bleach==1.4
dj-database-url==0.3.0
dj-static==0.0.6
Django==1.6.5
gunicorn==19.3.0
html5lib==0.9999999
Markdown==2.4.1
Pillow==2.4.0
psycopg2==2.6.1
python-decouple==2.2
six==1.9.0
South==0.8.4
static3==0.6.1
Unipath==1.0
Questions are:
Why does the logs periodically appear? I guess there is a background task running.But Celery package is not used here.
How to configure the logs, for example, displaying one more logs such as:
/followers/check/?_=9896886900907 HTTP/1.1
What do "?_" and the long string of numbers stand for? I can understand the "?first_feed=13" means the querying parameter in Django request object.
GET /notifications/check/?_=1443574208656
When Django is run in development mode (with runserver) it prints a line for all HTTP requests received to the console.
All of them are coming from the outside, browsers, feed readers...
The parameters you are wondering about are GET query parameters. The ? is the delimiter so, _ is the key of the argument.
In development mode the logging is defined by default. If you want to have logging on your production system or more logging, read https://docs.djangoproject.com/en/1.8/topics/logging/ .

Categories