output of SELECT in "hex" UTF-8 and matplotlib output error

Issue #96 resolved
Roger Nassar created an issue

Hi,

running a SQL select using ibm_db_dbi is showing in b'\xf2\xf0\xf1\xf9\xf0\xf5\xf2\xf8 format.

How can I change that?

Also, running the matplot sample (provided in the https://ibmsystemsmag.com/Power-Systems/11/2019/How-to-Start-ml-on-IBM-i article), give me the below error:

_tkinter.TclError: no display name and no $DISPLAY environment variable

I tried replacing TkAgg by Agg but it did not work.

Thank you,

Roger

NB: I could provide more details if needed.

Comments (9)

  1. Kevin Adler

    My guess is the value you are selecting is tagged with CCSID 65535 or is CHAR FOR BIT DATA. You’ll need to cast it to a character string with a convertible CCSID.

    As to the $DISPLAY issue, that’s usually due to X11 forwarding not being set up properly. I think you need to look at these instructions:

    To make it work, you have to make your sshd forwarding the GUI information from IBM i to your ssh client. This could be done to modify the sshd_config file under /QOpenSys/QIBM/ProdData/SC1/OpenSSH/etc/. The following line should be changed from

    # X11Forwarding no
    

    to

    X11Forwarding yes
    

    After this change restart your ssh server by STRTCPSVR and restart your client with following command. Please note “-Y” is necessary here.

    ssh -Y <yourname>@<ibmi system>
    

    If you’re running from Windows using Putty, this answer might help: https://superuser.com/a/119908. If you’re on macOS, you’ll need to install XQuartz: https://www.xquartz.org/ If you’re on Linux or another Unix-like system, your GUI should already support X11.

  2. Roger Nassar reporter

    Hi Kevin,

    Thanks for the quick reply.

    Comments: We have a bunch of files (or tables in SQL lingo) with ccsid 65535 (was default when the files were created - V1R1M2…

    Unless you have a better solution, I will have to find a way to test in SQL if CCSID = 65535, CAST it as you are suggesting.

    On the subject of the X11Forwarding, I had changed it already, but I am using putty, & dont know how to include the -Y in that case.

    Thanks again,

    Roger

  3. Kevin Adler

    There is no -Y option in Putty, you have to configure it through the GUI as shown in the superuser.com link I gave above. You also need to install and set up an X server, which is also linked in that answer.

  4. Kevin Adler

    Personally, I’ve found setting up X11 and forwarding to be a pain on Windows, so you may have better luck going to the Jupyter section. You can do the same thing there with matplotlib, but it shows up in the web browser instead of trying to draw a GUI remotely over the network.

  5. Roger Nassar reporter

    I tried it from jupyter & got

    TclError: no display name and no $DISPLAY environment variable
    

    What am I missing?

    Thanks

  6. Kevin Adler

    To run in Jupyter, you need to not tell it to use TK for the backend. ie. remove mpl.use("TkAgg"). Jupyter will automatically set up the correct backend for matplotlib to use.

    here’s an example

    import matplotlib.pyplot as plt
    
    plt.plot([1,3,2,4])
    plt.ylabel('some numbers')
    

  7. Log in to comment