Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode error #5336

Closed
TheLoserOFC opened this issue Dec 4, 2022 · 11 comments
Closed

Decode error #5336

TheLoserOFC opened this issue Dec 4, 2022 · 11 comments

Comments

@TheLoserOFC
Copy link

Describe the bug

I was making a GET request to get an API response, I passed the entire header correctly, Authorization: "Bearer " + Accept: "application/vnd.api+json"
the undecoded response, simply giving me the return 200 but with the json without decode.

The key I provided is temporary, it has a limit of 10 requests per minute.

To Reproduce

https://runkit.com/embed/n960ru9as00a

Code snippet

async function GetID() {
  const response = await axios.get('https://api.pubg.com/shards/steam/players?filter[playerNames]=30_ImZikkado', {
    headers: {
      'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI3NTkwNzJkMC01NTQwLTAxM2ItNWMwZC0wNjE4ZTJmOTc0NzgiLCJpc3MiOiJnYW1lbG9ja2VyIiwiaWF0IjoxNjcwMDc1ODk2LCJwdWIiOiJibHVlaG9sZSIsInRpdGxlIjoicHViZyIsImFwcCI6Ii0wNDA0Nzc3ZS0wZGU5LTQwOGEtOGRhMi03NDYyYmYzMjhkNzcifQ.SzVwnPhfB8f8CvBAMiw20XaUZ6IMirLb2Z39fGSZddk',
      'Accept': 'application/vnd.api+json'
    }
  })

  console.log(response.data)
}

Expected behavior

the json is returned correctly,

Axios Version

1.2.0

Adapter Version

No response

Browser

Chrome

Browser Version

No response

Node.js Version

v16.17.0

OS

Windows 10

Additional Library Versions

"dependencies": {
    "axios": "^1.2.0",
    "discord.js": "^14.7.1",
    "request": "^2.88.2"
  }

Additional context/Screenshots

Not Decoded:
https://cdn.discordapp.com/attachments/1047304334175633518/1048791314474475521/image.png

Decoded using the request library:
https://cdn.discordapp.com/attachments/1047304334175633518/1048791376080404530/image.png
@choimin9510
Copy link

Add axios.defaults.headers['Accept-Encoding'] = 'identity';

But, did it change suddenly?
OTL

@dalwadani
Copy link

dalwadani commented Dec 4, 2022

Add axios.defaults.headers['Accept-Encoding'] = 'identity';

But, did it change suddenly? OTL

👍
this solved the bug for us.

@lucaswerkmeister
Copy link

Simpler example that doesn’t require any authorization tokens:

require('axios').get('https://en.wikipedia.org/w/api.php?action=query&meta=siteinfo&format=json').then(r => console.log(r.data));

Standard MediaWiki API request. Logs proper JSON with axios 1.1.3 but garbled nonsense with axios 1.2.0. git bisect points to a3d9017 as the culprit, though I haven’t yet tracked down the bug inside it.

@lucaswerkmeister
Copy link

lucaswerkmeister commented Dec 4, 2022

Okay, I found the bug. The new code in #5250:

-        if (data && data.length === 0 && res.headers['content-encoding']) {
+        if ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {

requires that the content-length response header is set. If it isn’t (e.g. the API request I mentioned doesn’t respond with a content-length), then axios now silently deletes the content-encoding, even though there still is a nonempty response that must be decoded.

@lucaswerkmeister
Copy link

Though I think the old code was buggy too, just in a way that didn’t come up as often – data was referring to the request data, not the response data, if I’m not mistaken.

@lucaswerkmeister
Copy link

lucaswerkmeister commented Dec 4, 2022

Apparently this bug was actually already fixed in 9041c7d / #5306. (And had also previously been reported in #5328, I think.)

Can we have a release with the fix?

@TheLoserOFC
Copy link
Author

you can do the correction update yes.

@tm1000
Copy link

tm1000 commented Dec 6, 2022

1.2.1 has the fix

@jasonsaayman
Copy link
Member

Please try 1.2.1 if that does not work please open a new issue and mention me.

@paulhobbel
Copy link

Seems like I still sometimes get this error randomly

@TheLoserOFC
Copy link
Author

after the update here it was normal, there was no problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants