qtconsole
qtconsole copied to clipboard
Feature request: Make password mode "warning" a real warning not just a print statement
I have a small program which uses getpass to request password input from the user. Now, getpass doesn't successfully function within a qtconsole ... this is actually fine I don't care, but in my program I want to actually prevent a user from trying to type their password when it will be echoed, not just warn them about it.
Initially I thought I could simply 'catch' getpass's own GetPassWarning using warnings.filterwarnings
, but that failed completely. It turns out that within a qtconsole, getpass still thinks it can obfuscate the input so that warning isn't ever hit. Specifically, on Windows, import msvcrt
works fine. The problem is that getch
and getwch
don't behave.
There is what looks like a handy warning printed in the _readline
method of ConsoleWidget, but it's not actually a real warning so I can't catch it. Would it be possible to actually throw a Python warning so that it can be caught within a catch_warnings()
context? Otherwise I'm going to have to figure out how to distinguish a Jupyter console from a Jupyter qtconsole by hand.
A pull request is welcome for this.
Otherwise I'm going to have to figure out how to distinguish a Jupyter console from a Jupyter qtconsole by hand
This is technically not possible by running code in the kernel.
@ccordoba12 Great! Are there any guidelines for error or warning handling that I should know before I just stick in a warnings.warn? I'm totally willing to make a PR, but I ask because I don't see warnings used anywhere else in the overall qtconsole code. And while I found what I think is the right place, I'm not terribly familiar with how qtconsole manages the console IO.
This is technically not possible by running code in the kernel.
Ahhh. Well I guess that saves me the time I might have spent trying!
Are there any guidelines for error or warning handling that I should know before I just stick in a warnings.warn?
No, there are no specific guidelines for that.
Alrighty, I will take a stab at it, thank you.
@ccordoba12 I'm hoping to re-animate this a bit ... I've been busy but I just now got to trying this. I have a correct development environment set up and I added another prompt just to make sure that I am in fact using a locally-installed jupyter qtconsole.
However, it seems that putting a warnings.warn
statement in console_widget.py (line 2277) does absolutely nothing. No warning is shown, and any use of filterwarnings
in code being run from the qtconsole has no effect. I have absolutely no idea how to tie in a real warning here ... why do exceptions work but warnings don't?
Also having the issue here. Need to programmatically know if getpass
can be safely used or if an alternate method of querying the password should be adopted. Looks like a problem that qtconsole misleads getpass
in believing it can obfuscate the input when it cannot even if I cannot say whether the problem is in qtconsole or getpass. Either one of the two is needed IMHO: a true exception or warning can be obtained; or ipython
should provide means to query if its console can hide passwords beforehand.