How to access datastore information (Interactive Console)? - python

I am right now working in a project where I have two GAE servers. One for development, and the other one for production.
So I needed to access the datastore to run some queries because I need some high level information about the entities we have. The way I did on the development server was by the " URL/_ah/admin ", and there I used the Interactive Console to run my queries in the server.
But the reality is obviously that I need to run that queries in my production server, I tried to acces there the same way by "myapp.appspot.com/admin/interactive" but I am getting a "Page not found", I cant acces either with " URL/_ah/admin ".
So I looking for the easiest way for me to be able to run that queries, by now it seems that I have found two posible ways that I would like to check with you.
First, it seems that I could active that Interactive Console by:
- url: /admin/.*
script: google.appengine.ext.admin.application
login: admin
And then I would have acces on the URL "myapp.appspot.com/admin/interactive". Is that correct?
Second, I have also read about the remote_api and using the remote_shell as an Interactive Console with the server. Would that be harder? Can someone of you link me a guide to do that?
I havent tried anything yet, because I must be sure of what I am going to do since this is a live project.
Thanks a lot,
Jose.

This is only made for the development server.
You can find all the code that runs it in the source and then use them as custom admin console pages.
For example, in app.yaml, place
admin_console:
pages:
- name: Interactive Console
url: /admin/interactive
and for the URI
handlers:
- url: /admin/interactive|/admin/interactive/execute
script: google.appengine.ext.admin.application
login: admin
since the interactive page relies on a POST handler in execute.

Related

Entire Application in Django shuts down with single error

I am new to Python and django , I worked on C# and php as developer earlier.
My problem here is Entire Application in Django shuts down with single error.
for example i start my website with "python3 manage.py runserver 0.0.0.0:8000"
example:-- i have two pages home and register
1) if i make error in register page code(register.py) , It shuts down home page too. Is there a way to prevent that as in php and C# in both one page do not effect other.
2) how to work in django with team one errors full team hangs.
3) How to work with live working websites things may become too risky.
also i am not able to find article related to this.
kindly help

Django print in prod' server

I've gotten use to using print in my python code to show contents of variable and checking the shell output.
But i have now migrated all my work onto a online server. Pythonanywhere
I don't have the foggiest idea how to do the same now?
Can someone point me in the right direction?
Print to web console? To a file? Or even to the shell session?
Thanks
On production server your print statements will output log to your webserver log files
In case of pythonanywhere there are three log files
Access log:yourusername.pythonanywhere.com.access.log
Error log:yourusername.pythonanywhere.com.error.log
Server log:yourusername.pythonanywhere.com.server.log
those logs are accessible in your web tab page.
The logs you are looking for will be in server.log
As mentioned in Serjik's answer you can see the output of the console via the server log link on PythonAnywhere.
However the much better way to approach this is to use the Python logging module.. Using this module will solve many of these problems for you and solve many issues you may not have thought about (like thread safety). This lets you do things like filter log messages by severity and a whole bunch of other things.
To get started with that I would recommend having a look at the basic logging tutorial.

What is the url for the browser based interactive console for live appengine project?

I have a live appengine application (myapp.appspot.com). I would like to access (python) terminal like behaviour within a browser window. I recall someone showing me functionality but cannot seem to find documentation on it. The functionality looked similar to the interactive console available in the local development environment.
Does anyone know the url at which I can access this tool?
You have to add a handler for admin application:
- url: /admin.*
script: google.appengine.ext.admin.application
login: admin
Then you can access interactive console at /admin/interactive.
Its also possible with appstats, but you also have to add appstats_SHELL_OK = True in your appengine_config.py.

Django language select on Heroku using Gunicorn doesn’t work

I’m running a Django app on Heroku and have installed this piece of code: https://github.com/st4lk/django-solid-i18n-urls
It works just as expected on the Django built-in server, but when deployed to Heroku, I’m starting to see some really nasty problems.
I have Gunicorn running with multiple workers and if I use this code, the language preference starts to work randomly (I guess it depends which instance the request goes against).
For example if I have EN as the default (non-prefixed url) and DE as the second language, everything is working fine if I just browse the / urls. Now, if I switch to /de/ (manually enter URL or switch from the Django language switcher), the main / url starts to work intermittently – if I keep refreshing the page, I get either a 404 or the page in DE. But there’s no way to switch it back to using EN completely again. Same happens with all the other URLs as well, I get either a 404 or the corresponding page in DE. And there’s no way to force it back to EN, even from the Django’s set_language view.
If I never touch the /de/ urls, it works all very well without the prefixed URLs.
Does anyone have any ideas how to get this working also on Heroku and Gunicorn?
It turns out Gunicorn and the middleware override works fine, problem was with another piece of custom middleware.

Auth_token error at Facebook

i have been on this for the last 2 days with no result.
i am running my facebook app on my localhost with port-forwarding method.
i know my server setup is working fine as i can see the logs on the django runserver and dyndns log as well.
django is properly responding to calls as well.
the problem is as soon as the app authorizes with my user account, it straight follows to the page that says this:
Errors while loading page from application
The URL http://amitverma.dyndns.org/facebook_sample/?auth_token=817f8fbe99eff10582b634589de17b84 is not valid.
Please try again later. We appreciate your patience as the developers of app_test and Facebook resolve this issue. Thanks!
I am making a test app learning from facebook + django tutorial from here and here.
I am still getting this error and I have no idea what i am doing wrong...
Please help me out.
This often happens with a failed authentication. I'm not sure what the Python client libraries might look like, but with the PHP ones you generally make an authorization call against the library, something like $facebook->require_login().
With the PHP library, if this call fails to verify the user's Facebook session, then it automatically outputs HTML that will redirect the browser and try to re-establish the session, hence the auth_token parameter.
I suspect you're running into something similar. Try to isolate any authentication calls you're making, and use a Firefox extension like LiveHTTPHeaders to see if you are undergoing any redirects during the requests.
When you get that error, presuming you have debug=True in the Django settings and that your application is in development mode in Facebook, you can do View Source and see the entire Django error page that would normally display, including traceback. Facebook comment it out in the HTML so it doesn't show on the front end, but you can copy and paste it into a separate HTML file and view that in your browser to see the nice friendly Django error page which will definitely give you a clue as to what's going wrong.

Categories

Resources