question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

This library doesn't decode everything properly

See original GitHub issue

I’m using this piece of code to download a webpage (using request library) and decode everything (using your iconv-lite library). The loader function is for finding some elements from the body of the website, then returning them as a JavaScript object.

    request.get({url: url, encoding: null}, function(error, response, body) {
            // if webpage exists, process it, otherwise throw 'not found' error
            if (response.statusCode === 200) {
              body = iconv.decode(body, "iso-8859-1");
              const $ = cheerio.load(body);
              async function show() {
                var data = await loader.getDay($, date, html_tags, thumbs, res, image_thumbnail_size);
                res.send(JSON.stringify(data));
              }
              show();
            } else {
              res.status(404);
              res.send(JSON.stringify({"error":"No content for this date."}))
            }
          });

The pages are encoded in ISO-8859-1 format, and the content is looking normal, there are no bad chars. When I wasn’t using iconv-lite, some characters, eg. ü, were looking like this: �. Now, when I’m using the library like in the code provided above, most of the chars are looking good, but some, eg. š are an empty box, even though they’re displayed without any problems on the website.

I’m sure it’s not cheerio’s issue, because when I printed the output using res.send(body); or res.send(JSON.stringify({"body":body}));, the empty box character was still present there. If that’s important, I copied the empty box character to Google, and it has changed to š. Also, I tried to change output of Express using res.charset but that didn’t help.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
PawelPleskaczynskicommented, Oct 29, 2018

Yep, it’s working right now, so it was an issue with the website itself, not this library. Thanks for help! 😃

0reactions
PawelPleskaczynskicommented, Oct 29, 2018

https://validator.w3.org/nu/?doc=https%3A%2F%2Fapod.nasa.gov%2Fapod%2Fap170813.html

This website gave me pretty interesting results about the real charset used on the NASA website

Warning: Using windows-1252 instead of the declared encoding iso-8859-1.

When I get back home I’ll check if it’s working when I change iconv’s decoding to windows-1252.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is ERROR: The decoder library file does not exist. ? #9
Hi Carlini, I installed all the dependencies and downloaded the model from Mozilla. I think everything seems to work given that "Google take ......
Read more >
iconv-lite not decoding everything properly, even though I'm ...
I'm using this piece of code to download a webpage (using request library) and decode everything (using iconv-lite library).
Read more >
codecs — Codec registry and base classes — Python 3.11.1 ...
This module defines base classes for standard Python codecs (encoders and decoders) and provides access to the internal Python codec registry, which manages...
Read more >
The file could not be read. It may be corrupt or not licensed
"The file could not be read. It may be corrupt or not licensed" · 1. You're using a file from a Pack which...
Read more >
Frequently Asked Questions | WebP - Google Developers
WebP does not offer a progressive or interlaced decoding refresh in the JPEG or PNG sense. This is likely to put too much...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found