bug-gnubg
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cube-info dictionary type error on linux cli using Python 3.9.2


From: Jim Segrave
Subject: Re: Cube-info dictionary type error on linux cli using Python 3.9.2
Date: Sun, 20 Feb 2022 12:30:49 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0

When Pyhon moved from version 2 to version 3,a new feature meant to assist with international character sets was added . A python string was considered different from an array of bytes. SO now anywhree the python scrip expects a variable to bean array of bytes and it currenty has a string, it needs the string to be explicity converted to an array of bytes by sepecifying a character encoding. Generally (and I think this will apply with gnubg), For your exmple, I'm assuming gnubg.cubeinfo()i returnng a string, so myCubeInfo will have a Python type of 'str'. If instead you cast the result of gnubg.cubeinfo() to a type of bytes, things would work:

myCubeInfo = bytes(gnubg.cubeinf(), 'utf8')

The change fro Python2 to PYthon3 has been a nightmare for many users and this is one of themost common breakages


On 19/02/2022 11:53, Rose Menninger wrote:
Hi. First of all, thanks for your efforts in creating such a good software / 
package. I have been using gnubg cli in the last few years and really enjoyed 
it. But recently I have encountered a weird error.

Using Gnubg 1.06.002 on Debian 11 (wirh Python 3.9.2) and also on ubuntu 20.4 
lts (with Python 3.8.10), every Python script that uses “cube-info” dictionary 
as argument, gives this type error:
TypeError: expected bytes, str found

Steps to reproduce this error:
Using gnubg 1.06.002 and Python 3.9.2 on linux
1- start cli using “gnubg -t”
2- start a new game using “new game”
3- set turn using “set turn 1”
4- set dice using “set dice 6 2”
5- enter Python command line using “>”
6- passing cube-info dictionary to any of gnubg methods that accept it as 
argument. For example:
      myCubeInfo = gnubg.cubeinfo()
      gnubg.calcgammonprice(myCubeInfo)

Expected result: cube-info with updated gammon prices

Result:
TypeError: expected bytes, str found

Note that the same code was working on older versions on gnubg. This same exact 
code also works correctly on gnubg 1.06.002 on Mac OS using Python 2.7.18. So, 
this error seems to be related to Python > 3.8.10. I have also built latest cvs 
version from savannah on a fresh and updated debian 11, but still got this same 
exact error.

Also, every other gnubg method that accepts “cube-info” dictionary results in 
the same exact error (calcgammonprice, cfevaluate, eq2mwc…). Everything else 
works as expected as far as I can see.

I have been struggling with this error for 3 weeks, searching about it on 
different forums and reproducing it on different machines. Am I missing 
something?

Any help is greatly appreciated.
Thanks








reply via email to

[Prev in Thread] Current Thread [Next in Thread]