short version:
I am making a web kiosk that loads only one site. I want the browser to automatically go "back" (return to previous page) when it gets an error on the page it is loading. is this possible if so how would i make it work?
long version:
i am making a webpy program that accesses a WSDL. the webpy program is accessed from a raspberry pi set up to function as a touch kiosk. the user will not have access to a back button. i check to see if the WSDL is up and running when the program starts and when a user logs on. i do not check on every call to the WSDL because i worry the bandwidth might get overwhelming as i add users (100+). my fear is if the WSDL goes down after log in, iceweasel will load an error (404?) page and strand the user on that page. any ideas?
I would try making yourself a custom webpy error page that simply redirects the user back to the main page (probably using JavaScript). In your code.py:
def notfound():
return web.notfound("<script>window.location="http://some.com";<script>")
Related
Running Python 3.6 and I'm having a whole lot of issues logging to a site primarily due to captcha. I really only need to search up URLs and retrieve the html on the page but I need to be logged in for certain additional information to appear on the accessible URLs.
I was using urllib to read the URLs but now I was looking for a solution to login and then request information. The automatic route won't seem to work due to those issues, so I'm looking for a method by which I am already logged in on an open browser and python opens up new tabs to search for URLs (the searches can be hidden, they don't have to literally open up new tabs). It appears that when I open new tabs manually on the site it still shows i'm logged in so If i can manually log in each time i want to run the script and then work based off that, it would actually work just fine.
Thanks
I am making my first web app with Flask wherein a database of drinks is displayed on the front-end based on selected ingredients. Then the user selects a drink and an in-page pop-up appears with some drink info and a button "make", when the user hits "make" it calls some python code on the back end (Flask) to control GPIO on my raspberry pi to control some pumps.
Does this "make" need to call some route (e.g. /make/<drink>) in order to call the python function on the back end? I don't like the idea that any user could just enter the URL (example.com/make/<drink>) where is something in the database to force the machine to make the drink even if the proper ingredients are not loaded. Even if I did checking on the back end to ensure the user had selected ingredients were loaded, I want the user to have to user the interface instead of just entering URLs.
Is there a way so that the make button calls the python code without using a "dummy URL" for routing the button to the server?
As others mentioned, you can secure the endpoint so that a user has to provide credentials to issue a successful request to that endpoint.
In addition, your endpoint should be using proper HTTP semantics if its creating / updating data. i.e. POST to create a drink, PUT to update a drink. This will also protect you from someone just putting the URL into a browser since that is a GET request.
TL;DR
Secure the endpoint (if possible)
Add checks that the proper request body is provided
Use proper HTTP semantics
I am using Python and a javascript or php sdk.
To obtain the access_token - I follow the steps indicated on the docs page (https://developers.facebook.com/docs/authentication/). I pass the redirect url to dialog/oauth and obtained the access_token. Once this is done, all output html being sent back to the browser gets rendered into to a new page, leaving the facebook iframe/canvas. (fyi, all output is done thru the usual 'self.response.out.write' function call).
Seems the PHP sdk hides this and I can't find a way to get : http://www.facebook.com/dialog/oauth?client_id=%s&redirect_uri=%s" dialog to send the output from the redirected url to the iframe/canvas that triggered the application. This is a 'Page Tab' app (not a 'App on Facebook') so have set the "Page Tab Name" and "Page Tab Url" on the basic apps config page.
I have not implemented session yet and I am wondering if that is necessary to pass the iframe target as a state variable and have it passed back along with the redirect to the uri.
I have searched many posts/etc and no luck and any help would be much appreciated !!
Tab Page Application undocumented steps :
The confusing part is the CANVAS_PAGE_URL in the example. This needs to be the web-hosted app URL (e.g. https://www.appname.appspot.com/).. This not clearly defined..
If access_token and the user_id is not found on the signed_request an auth dialog needs to be done (as per the page documentation). This needs to be done thru the script top.location.ref to endure that it launches as a dialog. This goes to a new page overwriting the canvas (or the fan-page) that triggered the app.
When the user allows the permissions on the app, the app is called thru the tab-page-canvas-url?code=".....". At this point, a redirect needs to be done (which is not documented anywhere. I had to look at the php sdk code to figure this out (fbmain.php line 17) (redirect() in python and header() php). The redirect needs to take the url for the app on the fan page : http://www.facebook.com/FAN_PAGE_NAME?sk=app_nnnnnnn
It took many hours of research and digging to understand this and hope it helps (I see a lot of questions raised around page breaking out of the iframe/canvas) and the basic problem is the extra redirect step that FB does not document anywhere...
(mail me and I am happy to share python code that is now all working nicely)
It is stated elsewhere, but to make clear: the reason your app breaks out of facebook is because the authentication dialogs get away from the original apps.facebook.com url.
This may only happen with extended permissions as the new permissions screen is two pages instead of one.
Once the authorization process is complete, the browser is redirected to the fully qualified app url on your server.
The "fix" is to send the browser back to the Facebook app using it's http://apps.facebook.com/appname address.
[that doesn't seem like good "flow" to most people, but that is how it is right now. I think there may be a different route by using the "Authenticated Referrals" on the "Auth Dialog" page of the apps, but haven't used it yet]
I use the PHP SDK and here is what I do:
Check for the "state" request parameter when your redirct_url is called after authorization. Some people had suggested using the "code" parameter, but I do not see it being returned.
''
// after completing the first authorization, the redirect url may send users away from Facebook to the redirect url itself.
//This php code redirects them back to the app page
if (isset($_GET['state'])){ header("Location: http://apps.facebook.com/appname']); exit; }
If you know a better way, please let me know!
I am writing a CGI script in python 2.5 and I have run into an issue I cant solve.
My cgi script allows a user to into data into a html form and press refresh and the data gets successfully added. But it has turned out that if a user presses the refresh button on their browser the data that they inputted before gets added again. This is not the behaviour that I am looking for, and as such I would love to be able to redirect a user after a HTTP POST/GET request back to the main page.
This is of course naturally possible, by using the :
print "Location: www.website.here"
line in python. But I cannot do this as I need to be able to store messages between each refresh in order to be able to display information to the user.
These messages are essentially validation error messages, and if a user inputs wrong data and presses submit then my page should reload and print the error messages. I have this side of things working, but if I need to redirect using the above line, then I loose this.
So my question is are there any other possible ways to remove the option to refresh a html page using CGI and python, or am I looking at this all wrong and should I be trying to find a way to store my messages after a HTML redirect?
I assume you actually have two scenarios:
The user entered the data correctly; reloading the page would cause the added data to be added again (which is wrong); the user may be redirected to the start page.
The user did not enter the data correctly (there are error messages); reloading would cause the same message to be displayed again; redirect unacceptable.
I suppose you can issue a redirect only if the data validates, and display error messages in the other case.
If you have an option to migrate your CGI script to a modern web framework like Flask, Bottle, Django or Pyramid, I suggest you do so. This will give you session state and generally more convenient and modern environment.
A common way to do this is to store the pending messages for a given user on the server, associated with that user's session, and to display them the next time you deliver a page to that user.
Such messages are often called "Flash messages" (nothing to do with Adobe Flash) or "Session messages".
See the Django documentation for an idea of how you would do this in Django.
Your question is extremely confusing, because you say “press refresh” adds data. – You also don’t mention if your form is submitted via POST or GET (is it submitted at all??).
There is nothing that protects you from double entries (the user can always hit reload) if you don’t guard actively against them. One way is to deliver your form with some unique number and check if you already accepted submissions for that number.
And the other problem you face is as old as HTTP itself: session state. If you don’t want to start with session IDs or cookies, but need to carry your data through some pages, add all state to the URL all the time.
The new approach is to use AJAX, where your submit button is not going to submit classically anymore, but instead is going to execute some JavaScript in which you submit on a different (logical) connection, wait for the result and than change something in the still existing HTML page so that the user can see the result (e.g. adding a paragraph at a prominent place), but has the form still in front of him as is.
Is it possible for my python web app to provide an option the for user to automatically send jobs to the locally connected printer? Or will the user always have to use the browser to manually print out everything.
If your Python webapp is running inside a browser on the client machine, I don't see any other way than manually for the user.
Some workarounds you might want to investigate:
if you web app is installed on the client machine, you will be able to connect directly to the printer, as you have access to the underlying OS system.
you could potentially create a plugin that can be installed on the browser that does this for him, but I have no clue as how this works technically.
what is it that you want to print ? You could generate a pdf that contains everything that the user needs to print, in one go ?
You can serve to the user's browser a webpage that includes the necessary Javascript code to perform the printing if the user clicks to request it, as shown for example here (a pretty dated article, but the key idea of using Javascript to call window.print has not changed, and the article has some useful suggestions, e.g. on making a printer-friendly page; you can locate lots of other articles mentioning window.print with a web search, if you wish).
Calling window.print (from the Javascript part of the page that your Python server-side code will serve) will actually (in all browsers/OSs I know) bring up a print dialog, so the user gets system-appropriate options (picking a printer if he has several, maybe saving as PDF instead of doing an actual print if his system supports that, etc, etc).