-1

The sample of the code is as follows:

import cx_Oracle
db=cx_Oracle.connect('system','oracle','192.168.2.42:1521/dave')
print db.version

The returned error is

Traceback (most recent call last): 
File "<stdin>", line 3, in <module> UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 82-83: invalid continuation byte
4
  • 1
    You're making us guess where the error happens. Edit your question to include the entire error traceback output, including the reference to the line of your code which caused the error. Aug 22, 2017 at 1:03
  • Also edit your question to properly format that code. Your real program doesn't have it all on one line like that, does it? Aug 22, 2017 at 1:04
  • Traceback (most recent call last): File "<stdin>", line 3, in <module> UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 82-83: invalid continuation byte
    – Lily
    Aug 22, 2017 at 1:05
  • import cx_Oracle db=cx_Oracle.connect('system','oracle','192.168.2.42:1521/dave') print(db.version)
    – Lily
    Aug 22, 2017 at 1:07

2 Answers 2

0

Upgrade cx_Oracle:

python -m pip install cx_Oracle --upgrade

A problem that caused this error on some Windows environments was fixed in Version 6.0 rc 2. If this doesn't fix it, log an issue at https://github.com/oracle/python-cx_Oracle/issues.

0

Problem here is not with cx_Oracle itself but with system environment. I assume that the system is windows based, since it is the most probable case. And yes, the error returned is not descriptive at all and happens on very first row:

import cx_Oracle

What happens here is that python tries to import cx_Oracle's binary library (which is dll), it fails to do so for some reason and then windows returns native error description encoded in national local codepage (cp1251 for Russian in my case) instead of utf8 that python expects. One of the ways to see that reason:

try:
    import cx_Oracle
except Exception as ex:
    print(ex.object.decode('1251'))

btw.: cx_Oracle 6.0b2 does not have that problem resolved, neither I think it should

4
  • Yes, I am aware that Windows returns a native error description which is not in UTF-8. That is the issue that was resolved in cx_Oracle 6.0rc2. The text is then converted from the local codepage into UTF-8. I'd be interested in hearing why you think it shouldn't be resolved! Sep 9, 2017 at 3:50
  • Of course the issue should be resolved, as all of them :) It's just that, in my opinion, that is example of one leaky abstraction. Namely python import internals expecting that errors in load_dynamic would be utf encoded. So I may be wrong here, but for me it looks like that kind of things should be handled on some lower level (which is aware of system it operates in, encodings and so on). Sep 13, 2017 at 11:32
  • Many thanks for your work, btw. cx_Oracle is irreplaceable. Sep 13, 2017 at 11:39
  • You're welcome. And I understand what you are trying to say. I still think this particular problem should be solvable, though! We'll have to see once I get someone who can replicate the issue consistently and can explain what they have done -- and change code to identify the source of the issue and why my debugging messages aren't being displayed! Sep 13, 2017 at 21:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.