A pit that does not write an account ID or password in the source and is prompted at runtime. It's a very good library for security, but I'm addicted to it when using it in Python, so make a note of it.
Click here for the python and pip versions I tried.
$ python -V
Python 2.7.9
$ pip freeze | grep pit
pit==0.3
Click here for the minimum description.
import pit
opts = {
'require': {
'id': 'your id',
'password': 'your password',
}
}
account = pit.Pit.get('test.account', opts)
print account['id']
print account['password']
But when I actually run it, I get an error. For some reason, the editor does not start the first time it is executed. Since you have not entered both id and password, naturally you will get a KeyError when getting the value.
>>> import pit
>>>
>>> opts = {
... 'require': {
... 'id': 'your id',
... 'password': 'your password',
... }
... }
>>> account = pit.Pit.get('test.account', opts)
>>> print account['id']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'id'
In the default state, no editor was specified, so I had to specify vi.
if not os.environ.get('EDITOR'):
os.environ['EDITOR'] = 'vi'
Correct and execute. vi was started, it became possible to input, and it ended normally.
>>> import pit
>>> import os
>>>
>>> if not os.environ.get('EDITOR'):
... os.environ['EDITOR'] = 'vi'
...
>>> opts = {
... 'require': {
... 'id': 'your id',
... 'password': 'your password',
... }
... }
>>> account = pit.Pit.get('test.account', opts)
>>> print account['id']
hoge
>>> print account['password']
hogehoge
When you do this ...
from __future__ import absolute_import
from __future__ import unicode_literals
import pit
import os
if not os.environ.get('EDITOR'):
os.environ['EDITOR'] = 'vi'
opts = {
'require': {
'id': 'your id',
'password': 'your password',
}
}
account = pit.Pit.get('test.account', opts)
print account['id']
print account['password']
!!python/unicode 'id': !!python/unicode 'your id'
!!python/unicode 'password': !!python/unicode 'your password'
A mysterious character is added when entering id and password in vi. In conclusion, the problem was that this line was there, so deleting it will solve it.
from __future__ import unicode_literals
If you pass the unicode character as an argument, the character "!! python / unicode" will be displayed. So, even if you don't specify unicode_literals, the same phenomenon will occur even if you write it like this.
opts = {
u'require': {
u'id': u'your id',
u'password': u'your password',
}
}
account = pit.Pit.get('test.account', opts)
Recommended Posts