deno icon indicating copy to clipboard operation
deno copied to clipboard

Node compat doesn’t work for node-yahoo-finance2

Open sergeysolovev opened this issue 1 year ago • 7 comments

Deno: 1.37.1

import yf from 'npm:yahoo-finance2';
console.log(await yf.quoteSummary('AAPL'));

Crashes with the following:

error: Uncaught Error: Errors { invalid_mapping, disallowed_character }
    at Object.toASCII (node:punycode:5:14)
    at file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:44:34
    at Array.reduce (<anonymous>)
    at Object.internals.findRule (file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:41:26)
    at Object.exports.parse (file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:198:24)
    at Object.exports.get (file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:258:18)
    at Object.getPublicSuffix (file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/tough-cookie/4.1.3/lib/pubsuffix-psl.js:70:14)
    at permuteDomain (file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/tough-cookie/4.1.3/lib/permuteDomain.js:38:28)
    at MemoryCookieStore.findCookies (file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/tough-cookie/4.1.3/lib/memstore.js:99:21)
    at MemoryCookieStore.findCookies (file:///Users/sergees/Library/Caches/deno/npm/registry.npmjs.org/universalify/0.2.0/index.js:5:67)

Looks like an issue with deno according to https://github.com/gadicc/node-yahoo-finance2/issues/685

sergeysolovev avatar Oct 10 '23 07:10 sergeysolovev

Same issue for Node's PSL library (https://www.npmjs.com/package/psl).

error: Uncaught Error: Errors { invalid_mapping, disallowed_character }
    at Object.toASCII (node:punycode:5:14)
    at file:///.../Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:44:34
    at Array.reduce (<anonymous>)
    at Object.internals.findRule (.../Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:41:26)
    at Object.exports.parse (.../Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:198:24)
    at Object.exports.get (.../Caches/deno/npm/registry.npmjs.org/psl/1.9.0/index.js:258:18)
    ...   

acrodrig avatar Oct 20 '23 15:10 acrodrig

Hey, I'm facing the same issue, any luck on resolving it?

DDushkin avatar Jan 17 '24 21:01 DDushkin

@DDushkin I gave up immediately and haven’t tried it since then

sergeysolovev avatar Jan 18 '24 00:01 sergeysolovev

@DDushkin I gave up immediately and haven’t tried it since then

I see, maybe you found a different solution or library for getting quotes?

DDushkin avatar Jan 18 '24 05:01 DDushkin

Did a little digging and Deno stumbles when passing the string in this line to toASCII https://github.com/lupomontero/psl/blob/a789d0381c886da02eb8594da0761860657c08ba/data/rules.json#L929

"个��.hk"

Minimal reproduction:

import PunyCode from "node:punycode";
console.log(PunyCode.toASCII("个��.hk"));
// Node logs: xn--ciq6844ba.hk

marvinhagemeister avatar Jan 19 '24 11:01 marvinhagemeister

@DDushkin Yes I’m using alphavantage via their REST API

sergeysolovev avatar Jan 19 '24 14:01 sergeysolovev

Just came across this issue in the psl issue tracker. Looks like this is an encoding bug in the actual data.json file https://github.com/lupomontero/psl/issues/310

The official one from https://publicsuffix.org/list/public_suffix_list.dat doesn't have this issue.

marvinhagemeister avatar Jan 20 '24 10:01 marvinhagemeister

The original issue reported here should be fixed (by https://github.com/denoland/deno/pull/22847). I've confirmed the snippet in the initial report works correctly now.

Let us know if you continue to have issues with this!

nathanwhit avatar Jun 10 '24 19:06 nathanwhit