Error 400 when using Session ID to use the same IP for a second request

Posted about 6 years ago by webmastah

Post a topic
Answered
w
webmastah

Hi everyone.


Let's see if someone can help me out or, at least, point me in the right direction. I need to use X-Crawlera-Session headers so that I can send a second request to the same slave (IP).


For this, I use X-Crawlera-Session: create in the first request. And get the session ID correctly in the response. I parse the response and use this session id number as a header (X-Crawlera-Session: sessionId) in the second request.


However, the result is always an error 400 (invalid session id). I can't seem to find the error. Been struggling with it all day and looking for information in the forum and docs, but you can hardly find something for PHP.


Thanks everyone in advance!

2 Votes

nestor

nestor posted about 6 years ago Admin Best Answer

The problem is that the session ID that you're passing in the second request is incorrect.


You can use the list sessions endpoint to double check that the ID that you're storing the in the variable is correct https://doc.scrapinghub.com/crawlera.html#list-sessions. You also don't need to view the logs to see the session ID in the response, just print out the response headers.

0 Votes


7 Comments

Sorted by
w

webmastah posted about 6 years ago

Any chance of anyone who has faced the same issue? I would appreciate any help or hint... Thanks in avance!

0 Votes

t

trackrn6 posted about 6 years ago

I am having this same issue.



0 Votes

nestor

nestor posted about 6 years ago Admin

Most likely you're not storing/capturing the value of the session ID from response header properly.

I would suggest you print/output the response header and the value of your variable for the sessionID and see if they match.


Another reason for 400 error code is the session limit, but it comes with the message user_session_limit. C10 plans have only up to 100 active sessions.

0 Votes

w

webmastah posted about 6 years ago

  • Actually, Nestor, I am requestion the creation of the session (X-Crawlera-Session: create) and receive the sessionID correctly. I am outputting both the variable, as parsed by me, along with the response I receive and they do match. 

  • However, when I pass the header 'X-Crawlera-Session: 33176487090’ (note this id is just a sample ID) in the second request as a header (so that I can use the same IP for both requests), then I get this error denying the sessionID and, therefore, I cannot compare it with the one I already received in the first request.
  • I have tried checking in the admin and in the logs (created and downloaded in the CSV option), but they do not appear or do not include the sessionID.


Any idea what the problem can be? Thanks a lot in advance.

0 Votes

nestor

nestor posted about 6 years ago Admin Answer

The problem is that the session ID that you're passing in the second request is incorrect.


You can use the list sessions endpoint to double check that the ID that you're storing the in the variable is correct https://doc.scrapinghub.com/crawlera.html#list-sessions. You also don't need to view the logs to see the session ID in the response, just print out the response headers.

0 Votes

w

webmastah posted about 6 years ago

Great! Now it's working. I got to see the session ID's by using terminal instead of looking at the logs. It was a problem with the quotes. 


Thanks a lot and again! ;)

0 Votes

nestor

nestor posted about 6 years ago Admin

No problem.

0 Votes

Login to post a comment