Pylons: __call__ and abort(), error code 500 instead of requested code - pylons

I'm trying to use pylons.controllers.utils.abort() function to terminate application and return corresponding code to the browser. But the only returning code is 500 Internal Server Error if calling from controller's method call(). For example
class ApiController(WSGIController):
def __call__(self, environ, start_response):
abort(411)
What should I change to get normal server response with code 411?
Edit: Nevermind, looks like abort() is not supposed to be used in the __call__() method.

abort() is not working properly there so I'm using this code now:
return HTTPBadRequest()(environ, start_response)

Related

Service __len__ not found Unexpected error, recovered safely

python3.8
My code:
from googleads import adwords
def execute_request():
adwords_client = adwords.AdWordsClient.LoadFromStorage(path="google_general/googleads.yaml")
campaign_service = adwords_client.GetService('CampaignService', version='v201809')
pass
context["dict_list"] = execute_request()
Traceback:
Traceback (most recent call last):
File "/home/michael/pycharm-community-2019.3.2/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 282, in frame_vars_to_xml
xml += var_to_xml(v, str(k), evaluate_full_value=eval_full_val)
File "/home/michael/pycharm-community-2019.3.2/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 369, in var_to_xml
elif hasattr(v, "__len__") and not is_string(v):
File "/home/michael/PycharmProjects/ads3/venv/lib/python3.8/site-packages/googleads/common.py", line 694, in __getattr__
raise googleads.errors.GoogleAdsValueError('Service %s not found' % attr)
googleads.errors.GoogleAdsValueError: Service __len__ not found
Unexpected error, recovered safely.
googleads.yaml about logging
logging:
version: 1
disable_existing_loggers: False
formatters:
default_fmt:
format: ext://googleads.util.LOGGER_FORMAT
handlers:
default_handler:
class: logging.StreamHandler
formatter: default_fmt
level: DEBUG
loggers:
# Configure root logger
"":
handlers: [default_handler]
level: DEBUG
I've just started studying the API.
Namely, I'm trying to execute my first request (https://developers.google.com/adwords/api/docs/guides/first-api-call#make_your_first_api_call)
Could you help me with this problem? At least how to localize it more precisely.
This seems to be a problem which results from the way the PyCharm debugger inspects live objects during debugging.
Specifically, it checks if a given object has the __len__ attribute/method in the code of var_to_xml, most likely to determine an appropriate representation of the object for the debugger interface (which seems to require constructing an XML representation).
googleads service objects such as your campaign_service, however, use some magic to be able to call the defined SOAP methods on them without requiring to hard-code all of them. The code looks like this:
def __getattr__(self, attr):
"""Support service.method() syntax."""
if self._WsdlHasMethod(attr):
if attr not in self._method_proxies:
self._method_proxies[attr] = self._CreateMethod(attr)
return self._method_proxies[attr]
else:
raise googleads.errors.GoogleAdsValueError('Service %s not found' % attr)
This means that the debugger's check for a potential __len__ attribute is intercepted, and because the CampaignService does not have a SOAP operation called __len__, an exception is raised.
You can validate this by running your snippet in the regular way (i.e. not debugging it) and checking if that works.
An actual fix would seem to either require that PyCharm's debugger changes the way it inspects objects (not calling hasattr(v, "__len__")) or that googleads modifies the way it implements __getattr__, for example by actually implementing a __len__ method that just raises AttributeError.

Error running call reference function

I am having an error whilst trying to run a resource on a game server. I believe this line of code in the console is the issue;
Error running call reference function for resource es_extended:
citizen:/scripting/lua/scheduler.lua:351: server/main.lua:237: attempt to
index a nil value (global 'Async')
I have been to line 351 to find this;
error(err)
I then went to line 237 to find this;
Async.parallel(tasks, function(results)
I cannot see for the life of me anything wrong with either lines of code. So any and all advice is greatly recieved.
The global variable Async is a nil value. Hence indexing it like this:
Async.parallel
is not possible. Therefor Lua throws an error.
To fix it, find out why Async is nil and change that, or do not index it.

Showing parameter/arguments with Delphi Jedi JCLDebug

When an error occurs in my Delphi XE5 application, in my exception handler I am trying to get Jedi Code Library's JCLDebug.pas to show any parameters of method calls listed on the stack. I was hoping to get this information in a similar way to the way the Delphi IDE shows this information in its Call Stack debug window when you break during an exception, like this:
TestForm.DoSomething('A Test Parameter')
TestForm.TTestForm.DoSomethingClick($DF935B0)
VCL.Controls.TControl.Click
In my error handler, I get this a result similar to this with no parameter information:
[00F9701D]{Test.exe} TestForm.DoSomething$qqrx20System.UnicodeString (Line 138, "TestForm.pas")
[005E358B]{TestMonitor.exe} Vcl.Controls.TControl.Click$qqrv (Line 7340, "Vcl.Controls.pas")
I have initialised my error handling by calling during the units initialization section:
JclStackTrackingOptions:=JclStackTrackingOptions + [stStack, stRawMode];
JclStartExceptionTracking;
Then when the exception handler is invoked, I call the following to get the call stack strings:
JclLastExceptStackListToStrings(FErrors, True, False, False);
Is it possible to get the parameters the methods were called with using JCLDebug?

Handle Solr error messages from Blacklight

Whenever Solr fails executing a query for some reason it returns an error message and an error code. I would like to handle such errors in Blacklight. Right now, when receiving an error from Solr, the user gets a 500 internal error. As a developer I can see that what happens is an RSolr::Error::Http in CatalogController#index with the following line of code as the source of the problem:
res = blacklight_solr.send_and_receive(path, :params=>solr_params)
Is it possible to customize the error handling so that I can at least display an indicative error message to the user instead of the unhelpful 500 internal error?
Open file lib\blacklight\catalog.rb. The function rsolr_request_error(exception) is responsible to handle Solr errors. The exception parameter is an RSolr::RequestError and it represents the error from Solr. In order to handle the error by displaying the message from Solr just add the following inside the else:
error_status = eval(exception.response[:body])['error']
if !error_status.nil? and !error_status['msg'].nil?
flash_notice = error_status['msg']
else
flash_notice = I18n.t('blacklight.search.errors.request_error')
end
If you wish to display a different message then assign a different message to flash_notice. If you wish to handle the error differently then this is where to do so.

How do I use renderFile()?

I'm trying to make an action render to a file rather than output to the browser. I thought I would just have to do this:
return sfPHPView::renderFile('filename');
like I would with sfView, but that gives me an error:
Fatal error: Call to protected method sfPHPView::renderFile() from context...
What am I doing wrong?
Here's a link to the symfony API: sfPHPView::renderFile()
renderFile() is a method to render FROM a template file. That's why it isn't working.

Resources