Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not connect to FB services if set ISC_USER & ISC_PASSWORD by os.environ[ ... ] [PYFB69] #43

Closed
firebird-automations opened this issue Dec 6, 2016 · 11 comments

Comments

@firebird-automations
Copy link

Submitted by: @pavel-zotov

test #⁠1
#⁠#⁠#⁠#⁠#⁠

C:\>set isc_user
ISC_USER=SYSDBA

C:\>set isc_password
ISC_PASSWORD=masterke

C:\>python
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on
Python 2.7.8 (default, Jul 2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from fdb import services
>>> print( services.connect(host='localhost').get_home_directory() )
C:\MIX\firebird\fb40\
>>> ^Z

(OK, we able to connect to FB service manager using ISC_* environment variables that are assigned in OS command prompt)

test #⁠2
#⁠#⁠#⁠#⁠#⁠

C:\>set isc_user=
C:\>set isc_password=

C:\>python
...
>>> import os
>>> from fdb import services
>>>
>>> os.environ["ISC_USER"] = 'SYSDBA'
>>> os.environ["ISC_PASSWORD"] = 'masterke'
>>> print( services.connect(host='localhost').get_home_directory() )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\fdb\http://services.py", line 186, in connect
raise fdb.ProgrammingError('A password is required to use'
fdb.fbcore.ProgrammingError: A password is required to use the Services Manager.

Seems that inside python we can not use env. variables ? But they *are* defined:

>>> print os.environ.get('ISC_USER')
SYSDBA
>>> print os.environ.get('ISC_PASSWORD')
masterke

Commits: d7d5802 FirebirdSQL/fbt-repository@dab9229 FirebirdSQL/fbt-repository@740133f FirebirdSQL/fbt-repository@35f24c7 FirebirdSQL/fbt-repository@8bf47ed FirebirdSQL/fbt-repository@0926318 FirebirdSQL/fbt-repository@d9eaf16

@firebird-automations
Copy link
Author

Commented by: @pmakowski

read https://docs.python.org/2/library/os.html#process-parameters

you need putenv to change environment variables

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

Philippe, thank you for reply.
But why I did not encounter this problem before, when lot of tests like following were implemented:

import os
import subprocess

os.environ["ISC_USER"] = user_name
os.environ["ISC_PASSWORD"] = user_password

db_file="$(DATABASE_LOCATION)bugs.core_4337.fdb"

fn_nul = open(os.devnull, 'w')
subprocess.call([ "fbsvcmgr", "localhost:service_mgr",
"action_properties", "prp_write_mode", "prp_wm_async",
"dbname", db_file ],
stdout = fn_nul,
stderr = subprocess.STDOUT
)
fn_nul.close()
...

- ?

@firebird-automations
Copy link
Author

Commented by: @pcisar

It's not FDB problem, because FDB handles ISC_USER & ISC_PASSWORD in service calls just fine - if it's properly set before. Setting values to os.environ may not always work, see https://docs.python.org/2/library/os.html#os.environ

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

> FDB handles ISC_USER & ISC_PASSWORD in service calls just fine - if it's properly set before.
> Setting values to os.environ may not always work, see https://docs.python.org/2/library/os.html#os.environ

Setting values *DOES* work correctly, either via os.environ[] or os.putenv().
The problem is exactly in services.connect() function.

Pease see attached screen an following samples:

case-1: using os.putenv()
#⁠#⁠#⁠#⁠#⁠#⁠

C:\>set isc_user=

C:\>set isc_password=

C:\>python
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on
Python 2.7.8 (default, Jul 2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import subprocess
>>> from fdb import services
>>> subprocess.call(['fbsvcmgr','localhost:service_mgr','info_server_version','info_implementation'])
Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
1
>>> os.putenv('ISC_USER','SYSDBA')
>>> os.putenv('ISC_PASSWORD','masterkey')
>>> subprocess.call(['fbsvcmgr','localhost:service_mgr','info_server_version','info_implementation'])
Server version: WI-T4.0.0.463 Firebird 4.0 Unstable
Server implementation: Firebird/Windows/Intel/i386
0
>>> print( services.connect(host='localhost').get_home_directory() )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\fdb\http://services.py", line 186, in connect
raise fdb.ProgrammingError('A password is required to use'
fdb.fbcore.ProgrammingError: A password is required to use the Services Manager.
>>>

case-2: using os.environ[...] = ...
#⁠#⁠#⁠#⁠#⁠#⁠

C:\>set isc_user=

C:\>set isc_password=

C:\>python
ActivePython 2.7.8.10 (ActiveState Software Inc.) based on
Python 2.7.8 (default, Jul 2 2014, 19:50:44) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import subprocess
>>> from fdb import services
>>> subprocess.call(['fbsvcmgr','localhost:service_mgr','info_server_version','info_implementation'])
Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
1
>>> os.environ['ISC_USER']='SYSDBA'
>>> os.environ['ISC_PASSWORD']='masterkey'
>>> subprocess.call(['fbsvcmgr','localhost:service_mgr','info_server_version','info_implementation'])
Server version: WI-T4.0.0.463 Firebird 4.0 Unstable
Server implementation: Firebird/Windows/Intel/i386
0
>>> print( services.connect(host='localhost').get_home_directory() )
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\fdb\http://services.py", line 186, in connect
raise fdb.ProgrammingError('A password is required to use'
fdb.fbcore.ProgrammingError: A password is required to use the Services Manager.
>>>

@firebird-automations
Copy link
Author

Commented by: @pavel-zotov

Unfortunately, one can not attach file in this branch of tracker.
See screenshot here (if needed)

https://yadi.sk/i/xXc1durh32UqTU

@firebird-automations
Copy link
Author

Commented by: @pcisar

Well, I see where the problem is. FDB services.connect() reads environment variables on loading into memory (when you import fdb into python), not on call to it. So if you define environment variables at OS shell level or before fdb is imported, it works as expected. See:

> python
Python 2.7.12 (default, Jul 01 2016, 15:34:22) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ.get('ISC_PASSWORD')
>>> os.environ['ISC_PASSWORD'] = 'masterkey'
>>> os.environ.get('ISC_PASSWORD')
'masterkey'
>>> import fdb
>>> s = fdb.services.connect(host='localhost')
>>> s.get_home_directory()
'/opt/firebird/'
>>>

Because there is a clear anomaly how fdb.connect and fdb.services.connect handle environment variables, I'll fix services.connect to read environment on call, like fdb.connect/create_database does.

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Closed [ 6 ] => Reopened [ 4 ]

resolution: Won't Fix [ 2 ] =>

@firebird-automations
Copy link
Author

Modified by: @pcisar

Fix Version: 1.7 [ 10803 ]

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Reopened [ 4 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants