Giter Club home page Giter Club logo

Comments (6)

Holiverh avatar Holiverh commented on September 15, 2024

These changes will more or less be incorporated into a rewrite of the RCON module.

from python-valve.

CzBiX avatar CzBiX commented on September 15, 2024

My server is running on Linux, the player name in response may contains non-ascii char.
So I changed default encoding from ascii to utf-8 in rcon.py, and it works well.

And I just checked other libraries, all of that used utf-8 encoding.

from python-valve.

brandonsturgeon avatar brandonsturgeon commented on September 15, 2024

Any update on this one? I tried changing rcon.py from ascii to utf-8 and am presented with this error:

Unexpected message <RCONMessage 0 AUTH_RESPONSE 0B>
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 994-996: ordinal not in range(128)

Quite unhelpful. I'm not sure why ascii is even still being used.

I've tried pretty much everything mentioned in the docs. I can't run valve.rcon.RCON.execute() without this error - I don't even get a chance to encode/decode with my desired format.

from python-valve.

dieselburner avatar dieselburner commented on September 15, 2024

I've hit this issue yesterday. I have my own web interface for the server I'm running, which is dependent on this package. It was stable as hell until someone joined a server with a weird chars in his name. That's when simpe status request was crashing my app:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "./application.py", line 45, in decorator
    return f(*args, **kwargs)
  File "./application.py", line 73, in index
    data = rcon('status')
  File "/usr/local/lib/python2.7/dist-packages/valve/rcon.py", line 346, in __call__
    raise RCONMessageError("Couldn't decode response: {}".format(exc))
valve.rcon.RCONMessageError: Couldn't decode response: 'utf8' codec can't decode byte 0xd0 in position 359: invalid continuation byte

After looking into detalis a bit further it does not matter what encoding you are using - you might hit this issue in any case. IMO, quick (right?) solution would be to simply drop those chars that can't be encoded:

text.encode(encoding=self.ENCODING, errors='ignore')

I'll create a PR, and then it's up to you to decide what would be the correct way to do this.

from python-valve.

dieselburner avatar dieselburner commented on September 15, 2024

Here you go. Feel free to update a commit message if needed.

from python-valve.

ip2k avatar ip2k commented on September 15, 2024

For others who may find this in the future, this is what I found a solution in:

First, read https://python-valve.readthedocs.io/en/latest/rcon.html#unicode-and-string-encoding

with valve.rcon.RCON(server_address, password) as rcon:
    rcon_resp = rcon('status')
rcon_text = rcon_resp.body.decode('utf-8', 'ignore')

This works for me on a Ubuntu 18 LTS server running this under Python 3.6 against SRCDS running on the same instance.

from python-valve.

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.