Coder Social home page Coder Social logo

Comments (6)

KirillMysnik avatar KirillMysnik commented on May 30, 2024 1

Yes, it's possible to make it cross-pythonic. Usually the six package is used, but I think it's not even needed there.

urllib2's just got refactored (or maybe just renamed) to urllib.request in Python 3.

Since you mentioned generate_classes.py, I'ma open an issue related to it that I've discovered while trying to use obs-websocket-py for my needs.

from obs-websocket-py.

JohnnyBlaze420 avatar JohnnyBlaze420 commented on May 30, 2024

I'm no Python 3 expert yet, but I'll try to help out. Two issues so far: exceptions and password hashing, both in core.py

Syntax for exceptions changed from
except (ValueError, exceptions.ObjectError), e:
in Python 2 to
except (ValueError, exceptions.ObjectError) as e:
in Python 3.

With those changes the module works if the user doesn't use a password. With the password provided we have another problem - hashing. core.py at line 57 and 58 throws an exception:

secret = base64.b64encode(hashlib.sha256(password + result['salt']).digest())
TypeError: Unicode-objects must be encoded before hashing

as strings in Python 3 are now fully unicode from the start. I tried to fiddle with it yesterday but didn't find a solution yet. Encoding the password string beforehand does raise a string + bytes can't concat bytes to str type error, so... Little bit of magic is required somewhere. :)

from obs-websocket-py.

KirillMysnik avatar KirillMysnik commented on May 30, 2024

@JohnnyBlaze420
Here's what I made it look like in core.py (besides exception handling) to successfully connect to the secured OBS:

secret = base64.b64encode(hashlib.sha256((password + result['salt']).encode('utf-8')).digest())
auth = base64.b64encode(hashlib.sha256(secret + result['challenge'].encode('utf-8')).digest()).decode('utf-8')

auth needs to be decoded from bytes because it will go to the JSONed dict, and JSON can only handle strings, not byte strings. So I decode the result from b64encode as a UTF-8. Well, in fact, it can be decoded as an ASCII, because that's just base64 string.

EDIT:
Making it Python 3 compatible is not the same as making it Python 3 compatible while keeping Python 2 compatibility. That'd require a bit more work.
@Elektordi, do you want to keep Python 2 compatibility?

from obs-websocket-py.

Elektordi avatar Elektordi commented on May 30, 2024

I definitely need Py2 compatibility because I originally write this lib for a specific task which is running under Py2.7

But I just read https://wiki.python.org/moin/Python2orPython3#Supporting_Python_2_and_Python_3_in_a_common_code_base and there is some interesting advices to have a common Py2/Py3 code.

obs-websocket-py is a pretty simple project, it should be possible to make it work that way. You think so?

from obs-websocket-py.

Elektordi avatar Elektordi commented on May 30, 2024

I made some tests in python3 branch. Both samples seems to be working.
Have you got some other uses to test with?

(Only generate_classes.py is still not working, urllib2 was not ported to Python3 yet. But it's not an important part of the project...)

from obs-websocket-py.

Elektordi avatar Elektordi commented on May 30, 2024

Ok, made some tests with the python3 branch, no problems so far, I'm merging with master and aim at release 0.3 to be advertised on PyPI as Py3 compliant... :)

from obs-websocket-py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.