How can I activate the Flask debugger when running under mod_wsgi?
I have DEBUG, PROPAGATE_EXCEPTION and PRESERVE_CONTEXT_ON_EXCEPTION set to True, but still the debugger doesn't appear on exceptions.
As described in the Flask documentation at:
http://flask.pocoo.org/docs/quickstart/#debug-mode
use:
app.debug = True
Under mod_wsgi you aren't doing the app.run() though.
Ensure you are setting 'app.debug' at global scope and not in a conditional section where checking whether __name__ is __main__.
You may use interactive debugger provided by werkzeug:
from werkzeug.debug import DebuggedApplication
application = DebuggedApplication(app, True)
This is earley suggested by #jd work for me.
Related
I have an automatic test suite that uses Selenium to control a Chrome browser with a particular version. However Chrome tries to update itself between test runs. How do I prevent Chrome from automatically updating itself?
Removing write permission from the Google Chrome binary appears to prevent it from self-updating, at least on macOS.
In Python you can do that with code that looks like:
import subprocess
def remove_write_permissions(itempath: str) -> None:
subprocess.run([
'chmod',
'-R',
'a-w',
itempath
], check=True, capture_output=True)
remove_write_permissions('/Applications/Google Chrome.app')
I've only tested this code on macOS. It probably also works on Linux, but probably not Windows.
During the test, a file (.html) will be downloaded from the web application & I have to verify that file by opening it on the browser. In the non-headless mode, my test is working fine. But whenever I'm going to headless mode, that file is not getting downloaded to the download path (i.e. pointed in the "user.dir"). My chrome driver version is 2.44.609538 & selenium version is 3.14.
Apparently this could help you
Shawn Button post the answer related with it.
Downloading with chrome headless and selenium
Are you running the test from the command line?
Because, according to an answer to this question and this, when you run it via command line, your user.dir corresponds to your global user directory (C:\users\username).
This worked for our ruby implementation:
Capybara.register_driver :scrapping_driver do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')
options.add_argument('--disable-popup-blocking')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--window-size=1366,2000')
options.add_preference(:download, directory_upgrade: true,
prompt_for_download: false,
default_directory: "#{Rails.root}/")
options.add_preference(:browser, set_download_behavior: { behavior: 'allow' })
Selenium::WebDriver::Service.driver_path = Webdrivers::Chromedriver.driver_path
driver = Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Pay attention at download behaviour
I met same situation.
Headless mode is very faster. So your code might be implemented to detect download(DL).
Solution.
(Current your process?) .click for DL -> Detecting download file generation.
(My solution) Detecting download file generation -> .click for DL.
I implemented the above mechanism using callback function.
I'm attempting to get Uvicorn to automatically restart on detected file changes when launching programmatically, as it would when started from the command line with the --debug switch. The following statement is at the bottom of my api source code file and while Uvicorn starts and runs fine, it doesn't launch in reload mode. I've tried setting the debug parameter to various diffrent values: uvicorn.run(debug= 'true', 'True', 'yes' and True (python boolean), but nothing seems to work.
uvicorn.run(app,
host=run_config['api_host'],
port=run_config['api_port'],
log_level=run_config['log_level'],
debug='true')
EDIT: In reference to my comment on #howderek's answer: I've tried a modified version of the suggested code. While the server successfully starts, the code below doesn't turn on the reloader:
import uvicorn
from uvicorn.reloaders.statreload import StatReload
reloader = StatReload('debug')
reloader.run(uvicorn.run(app, host='localhost', port=9187, debug='true'))
The documentation states that you can just use reload=True.
Example:
uvicorn.run("example:app", port=5000, reload=True, access_log=False)
That is because the --debug flag does more than just set debug=True in the run function.
In the Uvicorn source it appears they are creating a StatReload which was imported from uvicorn.reloaders.statreload
I couldn't find any documentation regarding this feature, but it appears all you will need to do is take:
uvicorn.run(app,
host=run_config['api_host'],
port=run_config['api_port'],
log_level=run_config['log_level'],
debug='true')
and make it:
from uvicorn.reloaders.statreload import StatReload
from uvicorn.main import run, get_logger
reloader = StatReload(get_logger(run_config['log_level']))
reloader.run(run, {
'app': app,
'host': run_config['api_host'],
'port': run_config['api_port'],
'log_level': run_config['log_level'],
'debug': 'true'
})
In Scrapy, I was trying to incorporate the ImagesPipeline and run it, but it took me a while to notice the spelling mistakes in the settings. (It expects "IMAGES_STORE" but I typed to "IMAEGS_STORE"). I found that the ImagesPipeline was not loaded in the debug log, but the cause was not immediately understood. It is mysterious why it will not cause an error when running Scrapy.
It did not throw error because you can put your custom settings in settings.py of your choice.
So Scrapy thought that IMAEGS_STORE was some your custom variable and that maybe used somewhere.
You can put Keisuke_URAGO=123 in settings.py and scrapy will not throw error. This is what settings.py is meant to be.
Due to disabling Selenium's control flow in the future, I'm trying to write new specs using async/await.
To do this, I have to use SELENIUM_PROMISE_MANAGER: false config option, which is unfortunately making my old specs that use Promise Manager fail.
I've tried setting this option in beforeAllhook, but then I get the following error:
TypeError: Unable to create a managed promise instance: the promise manager has been disabled by the SELENIUM_PROMISE_MANAGER environment variable: undefined
If it's possible, I'd like to avoid having separate protractor conf files for async/non-async specs - it would make my grunt exec command even more complicated that it is now.
Is there any other option to set this flag only for one or few specs/suites?
Analysis:
The 'SELENIUM_PROMISE_MANAGER: false' in protractor config file should be global level, find a way to disable on spec level.
Possbile Solution:
add 'promise.USE_PROMISE_MANAGER = false' before spec use await, and revert to true at the end of spec. I'm not try as that, if it workable, please tell me.