Pyramid Cherrpy blank error page - error-handling

I have a small Pyramid application that by default used the waitress web server when I set it up. However I am now trying to switch to CherryPy since it works much better with sse.
But for uncaught exceptions I got a 500 error page with content in waitress, but using cherrypy the pages are just blank (the status is correctly 500 though).
The only thing I did to switch was to change the line:
use = egg:waitress#main
to
use = egg:pyramid#cherrypy
In the documentation for CherryPy I can read that I can set a custom error message for an unanticipated error. Tried that out but I saw no effect at all, the function is never called - I even tried to add a breakpoint to CherryPy's internal error response but it was not hit either.
I suspect something else is wrong though since I assume CherryPy should show "something" by default for a 500 page ?

I have attempted to reproduce the issue using the starter scaffold that comes with Pyramid, and made the following modification to the existing views.py that it comes with:
from pyramid.view import view_config
from pyramid.httpexceptions import HTTPInternalServerError
#view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
raise HTTPInternalServerError()
On both CherryPy and waitress this returns a page with the HTTPInternalServerError() on it including the text.
Changing the raise to:
raise ValueError('test')
However only shows something on the page if the pyramid_debugtoolbar is enabled, and the user accessing the URL is allowed to see the pyramid_debugtoolbar (this is controlled by the hosts setting for pyramid_debugtoolbar).
CherryPy does not have its own text. Unfortunately I don't see a way to use the _cp_config method of enabling custom error messages, as there is no way to set it up on the HTTP server that is used when using the CherrypyWSGIServer which is used by the Pyramid cherrypy entrypoint used by pserve.
What you can do, is set up a default exception view in Pyramid such as the following:
#view_config(context=Exception)
def exception_view(request):
request.response.status = 500
request.response.text = u'Something went very wrong. Sorry!'
return request.response
You can off course customise this exception view however you'd like. If this exception view raises however, you will be at the mercy of CherryPy who will serve you a blank page.

Related

Loading local TileFile layer in pydeck

Am trying to load a local TileFile layer in pydeck(0.5) in jupyter notebook
I am using the following code:
import pydeck as pdk
data ='https://localhost:/home/user/myfolder/tiles/{z}/{x}/{y}.png`
layer = pdk.Layer(
'TileLayer', # `type` positional argument is here
data=data
)
# Set the viewport location
view_state = pdk.ViewState(
longitude=50,
latitude=50,
zoom=0,
min_zoom=0,
max_zoom=5,
pitch=40.5,
bearing=-27.36)
# Combined all of it and render a viewport
r = pdk.Deck(layers=[layer], initial_view_state=view_state)
r.to_html('TileLayer-example.html'
This just creates a blank view window in Jupyter where it should show an image.
If I take launch the TileLayer-example.html independently into a browser I also get a blank window, However browser (Firefox) console output is as follows:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://localhost:/home/user/myfolder/tiles/0/0/0.png. (Reason: CORS request did not succeed).
TypeError: NetworkError when attempting to fetch resource. tile-layer.js:18:56
value tile-layer.js:18
value tile-layer.js:136
t tile-2d-header.js:90
u runtime.js:45
_invoke runtime.js:271
e runtime.js:97
Babel 2
r
u
I am not sure if the problem is CORS related (calling a local file) or if my data path is just plain wrong? I have tried may variants on path but all seem to have the same console warning issues.
Any suggestions for simple safe ways around the CoRs problem, or suggestions for accessing local TileFiles in PyDeck would be much appreciated
For other folk currently looking to implement TileLayer in Pydeck. It appears TileLayer is not yet documented or currently supported in pydeck and can only be achieved with a custom layer see this github issue and this suggested workaround with a custom layer
With respect to the CoRs issue of trying to display a local file resource in the browser when called from a URL. if you are looking for a quick fix to do a test/debug then in Firefox: the suggestions here help. For Firefox specifically they suggest the following:
go to about:config
search for privacy.file_unique_origin
set it to false.
Note this is a security risk so reset it to true after debugging.
The only workable solution currently seems to be to put the tilefile in the working directory from which your deck project is launched

cakephp 2 non existing controller and files could not be found

I make debug on a website running on cakephp 2 (yes it's old i know)
I have strange errors i cannot resolve.
in log i have:
-Error: [MissingControllerException] Controller class Wp-login.phpController could not be found
-Error: [MissingControllerException] Controller ColonisersController could not be found.
-Error: [MissingActionException] Action ImgController::ui-bg_diagonals-thick_90_eeeeee_40x40.png() could not be found.
-Error: [MissingActionException] Action ImgController::moustique-tigre-default.png() could not be found.
...
I search over all the source code for Colonisers but it is not write even once (also i think ColonisersController is a renammed controller because it is misspelled).
I search over the web for the Wp-login.php and it is a wordpress page, so no link to cakephp at all, also not write anywhere in the source code.
Same story for the missings pngs files. not in the source code.
I try to clear the cache folder on server but problems remains.
I have ghost source code? file are somewhere in another cache ?
any idea are welcomed.
By default all request that do not map to an actual file are being passed over to CakePHP, where the app will try to match the request to a route, and if one is found, finally try to match it to a controller and an action.
You seem to have some rather unspecific routes defined that eat pretty much anything as a possible controller name, hence things are being passed further for searching for a matching a controller and an action, which is where the request flow will end, as no matching controller or action can be found - consequently a MissingControllerException or MissingActionException is being triggered, an error is being logged (by default all exceptions are being logged), and in production mode (debug = 0) the app will respond with a 404 error.
So, no ghosts, no cached files, that's just how things work.

How to handle 500 server errors in Umbraco

I just want a custom error page when a server error occurs - I've tried endless combinations of suggestions that I've found on google but nothing even begins to get me there.
Essentially, I have some error handling routines in my surface controllers where I want to log the error & then throw the exception so that somewhere down the line a 500 response code is returned & a custom error page is displayed.
try
{
repository.AddShoppingCartItem(sci);
}
catch(Exception e)
{
Log.Error("whatever...");
throw;
}
Then in my web.config I've tried
<customErrors mode="On" defaultRedirect="error500">
</customErrors>
and
<customErrors mode="On" defaultRedirect="umbraco/surface/error500surface">
</customErrors>
(where the 1st version uses a regular controller & the second a surface controller)
Neither do anything.
I've also added this line as others have suggested but it makes no difference:
What I get is my normal layout page getting rendered along with this message:
Error loading Partial View script (file: ~/Views/MacroPartials/Addcart.cshtml)
what I want to happen is for a custom error page to be displayed instead.
Reading all the stuff on google, I'm completely confused as to whether I need to configure Umbraco to handle these errors or whether it's a pure MVC approach. I get the impression that 404 errors are done through umbraco but 500 errors need to be a pure MVC approach. Don't know if anyone can confirm this. Either way, something up the chain is swallowing my throw statement & I don't know what it is.
I've also tried
return new HttpStatusCodeResult(500);
in place of the throw & that just gets me a nasty IIS error page.
Any help would be most appreciated as this is driving me nuts.
500 errors are server errors and no different in Umbraco than in regular IIS:
This is a server error and can only be solved by website admin who has access to files and the web-server. There can be one of/or multiple reasons to get this error. One has to track down the issue and handle accordingly.
http://www.codeproject.com/Articles/545054/HTTPplus-plus-e-plusInternalplusserverplus
More info:
https://serverfault.com/questions/407954/how-to-diagnose-a-500-internal-server-error-on-iis-7-5-when-nothing-is-written-t
Edit: apparently you may be able to enable custom errors like so:
http://helpnotes.vpasp.com/kb/611-General-hosting-questions/1089-How-to-Turn-Off-Friendly-Error-in-IIS-7xx/
Edit2: This may be of interest as well:
http://benfoster.io/blog/aspnet-mvc-custom-error-pages

Alternative to Controller.flash in Play! 1.2.4

I currently use Play Framework's Controller.flash to set my errors before rendering.
As a result, the displayed error is often shown during 2 navigation steps. It is the expected behaviour since I don't always redirect.
So my question is : Does Play provides a way to handle simple render errors (like flash is handling redirect errors) ?
Or shall I manage my own error parameter ? Or shall I always ensure that I redirect ?
The flash scope is only for redirecting to another page. If you don't redirect, but call the render() method directly, then simply don't use flash. The error will automatically be available in you view.

Secured and unsecured items message in IE

I'm getting "This page contains bothe Secure and Non secure items"message in IE. When I commented the following piece of code from dojo.js.uncompressed.js file, the message is gone.
if(dojo.isIE){
if(!dojo.config.afterOnLoad){
document.write('<scr'+'ipt defer src="//:" '
+ 'onreadystatechange="if(this.readyState==\'complete\'){' + dojo._scopeName + '._loadInit();}">'
+ '</scr'+'ipt>'
);
}
Is that an issue with the dojo? I would like to move the commented code to another custom file so that the dojo framework is not affected. Can you suggest a better way of implementing it.
Thanks.
You would get that error if you're using frames or have external files where some of the files have https URLs while some have http URLs. Assuming, your main page loads up through https, you could try changing:
src="//:"
to:
src="https//:"
the //: is most likely the problem, as I ran into a similar issue with a chunk of javascript code... In internet explorer, the locaiton //: is not secure, so when your page (presumably on an https:// url) loads, IE notes that you've got your main code loading from a secure location, and another script being loaded in from an unsecure location.
The workaround that I came to was to create an empty file in my web root named "blank.html" (though "blank.js" would probably work better in your case) and replace the //: link with "/blank.html". This results in another hit to your webserver, but browser caching will probably make that impact minimal.