axios: Error response data nodejs
Describe the bug
` var axios = require(‘axios’); var data = JSON.stringify({ “production_status”: “”, “package_status”: [], “extra_status_reason”: [], “page”: 1, “limit”: 1 });
var config = { method: ‘post’, url: ‘https://example.com/’, headers: { ‘Authorization’: ‘Bearer token’, }, data: { “production_status”: “”, “package_status”: [], “extra_status_reason”: [], “page”: 1, “limit”: 1 } };
axios(config) .then(function (response) { console.log(response.data); }) .catch(function (error) { console.log(error); }); `
When i send API this response I want respose must be json like that
To Reproduce
No response
Code snippet
No response
Expected behavior
No response
Axios Version
1.2.0
Adapter Version
No response
Browser
No response
Browser Version
No response
Node.js Version
14.20.1
OS
No response
Additional Library Versions
No response
Additional context/Screenshots
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 71
- Comments: 58 (2 by maintainers)
Commits related to this issue
- Temporarily pin axios to 1.1.3 to avoid https://github.com/axios/axios/issues/5298 — committed to Consensys/solc-typed-ast by cd1m0 2 years ago
- :pushpin: Pin dependencies after issues with Axios 1.2.0 (https://github.com/axios/axios/issues/5298) — committed to mikesprague/packages by mikesprague 2 years ago
- fix(deps): downgrade axios https://github.com/axios/axios/issues/5298 — committed to hahnprojects/flow by 3fd 2 years ago
- fix(deps): downgrade axios https://github.com/axios/axios/issues/5298 — committed to hahnprojects/flow by 3fd 2 years ago
- Downgrad axios from 1.2.0 to 1.1.3 b/c of response errors See: https://github.com/axios/axios/issues/5298 — committed to inpercima/swaaplate by inpercima 2 years ago
- fix(deps): downgrade axios (#182) https://github.com/axios/axios/issues/5298 — committed to hahnprojects/flow by 3fd 2 years ago
- fix: downgrade axios to 1.1.3 axios/axios#5298 — committed to leifarriens/diedreifragezeichen-db by leifarriens 2 years ago
- Revert "Bump axios from 1.1.3 to 1.2.0 in /canaries (#805)" This reverts commit 3ea213719c2cdd611ad8118b163211002b0f5774. See https://github.com/axios/axios/issues/5298 — committed to aws-samples/aws-reinvent-trivia-game by clareliguori 2 years ago
- Revert "Bump axios from 1.1.3 to 1.2.0 in /chat-bot/bot (#804)" This reverts commit 77e8e94e5927473c321427c9a99a859522352073. See https://github.com/axios/axios/issues/5298 — committed to aws-samples/aws-reinvent-trivia-game by clareliguori 2 years ago
- chore(deps): ⬇️ downgrade axios due to issue https://github.com/axios/axios/issues/5298 — committed to CU-CommunityApps/ct-az-common-alert-endpoint by mikesprague 2 years ago
- fix: Sove very annoying axios bug. <https://github.com/axios/axios/issues/5298> — committed to quantified-uncertainty/metaforecast by NunoSempere a year ago
- axios@1 The previous `~1.1` range was to work around https://github.com/axios/axios/issues/5298. — committed to derhuerst/vbb-rest by derhuerst 4 months ago
Indeed, that workaround works in my case… based upon https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding I select
identity
:I spent my whole day because of this problem…😩
The problem is caused by https://github.com/axios/axios/pull/5250 cc @DigitalBrainJS @jasonsaayman
at this line:
If
res.headers
does not contain acontent-length
entry, thenresponeLength
will beNaN
In that case this line:
Will cause a
content-encoding
header to be deleted and as a consequence axios will no longer unzip the response.Can a maintainer confirm that manually adding
Accept-Encoding: identity
to every GET request is not the intended way to use axios (i.e., this issue is a regression)?https://github.com/axios/axios/blob/a3d901777bc06e78adae3081f694cdbf76241303/test/unit/adapters/http.js#L469
@macductan Closing the issue without a fix is a bit misleading. And the workaround is far from ideal.
Maybe you’d consider reopening the issue until this is actually fixed?
The temporary workaround is to set
Accept-Encoding
header to something other thangzip, deflate, be
-application/json
for instance. And loose compressed data exchange of course.I spent my entire day because of this same problem and fixed it by downgrading Axios to 1.1.3 🤣
.
this is ridiculous, other dependencies are reliant and system is down since yesterday
Try the latest release v1.2.1 please
Why has this been closed as completed? The issue still persists in
axios@1.3.0
. I don’t think that setting theAccept-Encoding: identify
explicitly should be the favored solution.The best solution is to go back to previous version 1.1.3 and wait for 1.2 to fix. There’s already a commit awaiting approval it seems to me.
I’ve started migrating all my applications to
fetch
https://blog.logrocket.com/fetch-api-node-js/Ditto with GET https://lichess.org/api/user/Toadofsky?trophies=true
Routing through proxy server BeeCeptor I can observe that Lichess response data are valid, however axios 1.2.0 does not handle the gzip encoding:
I’m getting the same error after upgrading to 1.2.0 😦
More discussion here: #5296
No its close cause the PR that has the fix has been merged, this is how GitHub works. I will release this weekend
+1 @macductan, I saw you closed this issue. When do you think the fix be released? Thanks!
i downgraded axios to ^0.19.2 it works now
1.2.1 fixed issue, thanks. Drove me insane for hours…
You can always downgrade axios with no problems.
For those fixing this by downgrading to
1.1.3
, if you are using typescript you may want to downgrade further to1.1.0
to avoid https://github.com/axios/axios/issues/5011For those that want to upgrade right now, use
1.2.0-alpha.1
(npm i axios@next
)I have the same problem after updating from 1.1.3 to 1.2.0
Downgrade to
"axios": "1.1.3"
for now.Thanks @cetteup, I thought @macductan has already fixed that issue and closed it. If not, then it will be better to keep it opened since the workaround is not ideal because this issue regresses axios unzip feature for the returned result.
Same here. Locally it works, but not in a production env. I am getting the following response:
Setting “‘Accept-Encoding’: ‘identity’” in the headers resolves the problem (as a workaround).
Experienced this too, breaks the whole app. Downgraded to 1.1.3 for now. Interested in hearing if there is a recommended fix going forward.
We too are experiencing this issue.
Am I right in thinking that
Accept-Encoding: identity
is not a good fix as this would disable all encoding in HTTP responses, dramatically impacting performance?We need a proper fix for this.
spent hours to find this page 🤣 change
package.json
version foraxios
to lower"axios": "~1.1.0"
and wait for the fix to be releasedThank you!! This fixed it!
I have the same problem since upgrading to 1.2.0