omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Can stash convert a curl document to utf-8?

    Pythonista
    curl utf-8 stash
    2
    3
    2683
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • djl
      djl last edited by djl

      I am trying to fetch a json document that has utf-16 accented vowels and convert it to utf-8 on the output file. I have a command line in the format:

      curl "url" -H "X-API-Key: key-goes-here" -o outfile.json
      

      I can't figure out where to add something like ' .encode(utf-8)' on the command line in order to convert to utf-8. Some say this kind of command line could solve the problem:

      curl URL | iconv -f iso8859-1 -t utf-8 > output.xml
      

      But stash curl does not accept iconv , -f, or -t arguments. Is there a way to make this work in stash?

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        sounds like a good improvement to curl, or create a new iconv command! see stash/bin and go to town!

        1 Reply Last reply Reply Quote 0
        • djl
          djl last edited by djl

          I thought of a workaround which is superior for my purposes. Redirect the downloaded file to the console:

          curl "url" -H "X-API-Key: key-goes-here" > &3
          

          Where it can be copied and pasted to a new file. If can be then read like this:

          with open('outfile.json, 'r',encoding='UTF-8') as f:
          

          This has the real advantage of preserving all of the accented vowels, etc. in the rest of the data processing. It turns out the original file was indeed UTF-8, but could not be handled by the ASCII decoder.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors