Skip to content

Unable to convert string to the requested encoding when reading sav files with long strings #241

Description

@ofajardo

Hi,

When reading a sav file that contains a long string (756 characters to be precise, with 755 the error does not show up) with an international character, Readstat gives the error:

Unable to convert string to the requested encoding (invalid byte sequence)

Attached an example save file. The sav file was produced with pyreadstat.

thanks in advance!

original report: Roche/pyreadstat#128

note: initially I reported the error was on writing, it is on reading!

eg.sav.zip

also attached a csv version of the file

eg.csv

Activity

  1. changed the title [-]Unable to convert string to the requested encoding when writing sav files with long strings with international characters[/-] [+]Unable to convert string to the requested encoding when reading sav files with long strings with international characters[/+] on Apr 23, 2021
  2. ofajardo commented on Apr 23, 2021

    @ofajardo
    Author

    another observation is that a very similar file with only one character of difference (first variable name "aaaaa3" instead of "aaaaa2") does not raise the error, attached example file.
    eg3.sav.zip

  3. evanmiller commented on Apr 23, 2021

    @evanmiller
    Contributor

    Are UTF-8 strings being provided to the writer?

  4. ofajardo commented on Apr 23, 2021

    @ofajardo
    Author

    Yes

  5. changed the title [-]Unable to convert string to the requested encoding when reading sav files with long strings with international characters[/-] [+]Unable to convert string to the requested encoding when reading sav files with long strings[/+] on Dec 15, 2021
  6. ofajardo commented on Dec 15, 2021

    @ofajardo
    Author

    as mentioned in #260, it is possible to reproduce this error without any international character, (using only 'a's in this example) if the length of the string is at least 757. Another important thing to reproduce this is that the numerical values must be NANs. See #260 for C code to reproduce the issue.

  7. jacob-lee commented on Aug 22, 2024

    @jacob-lee

    is this likely to be fixed?

  8. evanmiller commented on May 23, 2025

    @evanmiller
    Contributor

    Should be fixed in 3cab443

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions