0

I am trying to do the same request from nodejs. The python code is

import requests
 r = requests.post(url,
                              data=data,
                              headers={
                                  'User-Agent': self.ua,
                                  'Content-Type': 'application/x-www-form-urlencoded'
                              }
                              )

and in node I tried node-fetch and Axios and request but not getting the same response, I also tried CURL from bash but getting the same response of node, I tried to print python headers print(r.request.headers) and copy paste it in node but getting different response

Axios.post(url, {
      data,
      headers: {
        "User-Agent":
          "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
        "Content-Type": "application/x-www-form-urlencoded",


}
    })
      .then(text => console.log(text.data))
      .catch(err => {
        console.log(err);
      });

I am getting different result in python I get what I expect but in node I am getting html response

 Sorry, could not complete request because: <div class="tk-intro" style="font-size: 14px;color:#ff090f;">application information was not supplied.</div> 

but in python works fine

  • This will require a lot more explanation. Perhaps you will have to edit the code and provide more code/context – cross19xx Feb 27 '20 at 20:02
  • I passing the same data and same url and same headers but it works perfectly on python and fails in node and postman – Abanoub Istfanous Feb 27 '20 at 20:03
  • @AbanoubIstfanous, try to proxify each request and compare both requests line by line. – Olvin Roght Feb 27 '20 at 20:06
  • @AbanoubIstfanous I don't think that's enough information. What do you mean by _fails_ ? In any case, we don't have the output or a [mcve], I'm not sure how much we can realistically do. – AMC Feb 27 '20 at 20:07
  • @AMC I am getting different result in python I get what I expect but in node I am getting html response Sorry, could not complete request because:
    application information was not supplied.
    but in python works fine
    – Abanoub Istfanous Feb 27 '20 at 20:10
  • the point is I am putting the same data and headers and url but getting different result, IDK if python requests has default headers or node have that – Abanoub Istfanous Feb 27 '20 at 20:11
  • 1
    Please do not share that kind of information as a comment, it's very difficult to read. Edit your post instead. – AMC Feb 27 '20 at 20:15
  • Are you sure that `data` is identical in both cases? The axios response looks suspiciously like the error you would get with an empty or incorrect POST. – match Feb 27 '20 at 21:12
  • I found the problem and past it as answer – Abanoub Istfanous Feb 27 '20 at 21:17

1 Answers1

0

I tried to print request headers and url and data and found I should to to convert data to query string like that

"appleId=email@gmail.com&accountPassword=xxxxxx"

instead of passing it as JSON

{
"appleID": "email@gmail.com",
"accountPassword": "xxxx"
}
Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58