Request times out, cURL does not

riders994

I'm trying to pull the play by play from NBA STATS api using the python requests package. I kept running in to timeout errors, so I tried it in cURL.

Here's the url for the request of the single game I'm trying to get:

http://stats.nba.com/stats/playbyplayv2?EndPeriod=10&GameID=0021500492&StartPeriod=1

You can go to this link, check it out, everything on that end works.

I tried doing a cURL request to just that link, and it timed out. Eventually, I inserted the Request Headers as cURL parameters one by one until it worked.

curl -X GET -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0" -H "Accept-Language: en-US,en;q=0.5" -H "Accept-Encoding: gzip, deflate" "http://stats.nba.com/stats/playbyplayv2?EndPeriod=10&GameID=0021500492&StartPeriod=1"

Here's my query in requests:

pars = {'Accept-Encoding': 'gzip, deflate'\ , 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0'\ , 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'\ , 'Accept-Language':'en-US,en;q=0.5'} response = requests.get('http://stats.nba.com/stats/playbyplayv2?EndPeriod=10&GameID=0021500492&StartPeriod=1'\ , params=pars)

I either need to get this working in python through requests, or figure out a way to do this in cURL in such a way that I can (a) fill in the GameID part based on text from a file/filename in a loop and (b) save it as a json in the correct directory (not working directory).

Any ideas? Is there a urllib based solution?

ftg_air

You're passing header information as parameters. You need to pass it through headers.

import requests

headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) 
Gecko/20100101 Firefox/53.0'}

params = {
    'EndPeriod': 10,
    'GameID': '0021500492',
    'StartPeriod': 1
}
r = requests.get("http://stats.nba.com/stats/playbyplayv2", params=params, 
headers=headers)
print(r.json())

The params in requests is used to pass in parameter information to the API in order for the API to process your request on their end. Whereas Headers are used to authenticate or interpret your request.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Curl request to same server intermittently times out

From Dev

ajax GET request times out for URL when browser and CURL work

From Dev

ajax GET request times out for URL when browser and CURL work

From Dev

Mock a HTTP request that times out with HTTPretty

From Dev

NodeJS/MongoDB POST request times out

From Java

How do I measure request and response times at once using cURL?

From Dev

Conky runs the same curl request multiple times per interval

From Dev

Can't figure out why this ajax request fires two times

From Dev

Elasticsearch times out on every search request until restart

From Dev

Can't figure out why this ajax request fires two times

From Dev

Server request for audio file times out before returning any data

From Dev

node-http-proxy POST request times out

From Dev

iOS: HTTP POST request times out when setting httpBody property

From Dev

Why does a cURL request return a percent sign (%) with every request in ZSH?

From Dev

Sleep 3 seconds before sending out next request using CURL

From Dev

Why does a cURL request from a PHP file not work, when the same cURL request from the Linux console does?

From Dev

Does conn.SetDeadline() close the connection if it times out

From Dev

when connection times out using curl or get_file_contents to an API it kills my script

From Dev

GET Request works with python 'requests' library, but does not work with curl

From Dev

Does CURL GET recipient see the file making the GET request?

From Dev

request.META does not contain header passed from curl -H

From Dev

Why does a custom curl HEAD request hang for weebly.com?

From Dev

elasticsearch-php update returns bad request where curl does not

From Dev

Does `curl -v` show the complete HTTP request including the body?

From Dev

Looping by replacing the values in a file and then doing curl request for 25 times increasing count by 1000

From Dev

curl timeout eight times

From Dev

Working out the number of times a (request handler) function has been called in Go

From Dev

In Swift, when using dataTaskWithRequest the completionHandler returns a nil NSURLResponse when the request times out

From Dev

What is the best way to handle Invalid CSRF token found in the request when session times out in Spring security

Related Related

  1. 1

    Curl request to same server intermittently times out

  2. 2

    ajax GET request times out for URL when browser and CURL work

  3. 3

    ajax GET request times out for URL when browser and CURL work

  4. 4

    Mock a HTTP request that times out with HTTPretty

  5. 5

    NodeJS/MongoDB POST request times out

  6. 6

    How do I measure request and response times at once using cURL?

  7. 7

    Conky runs the same curl request multiple times per interval

  8. 8

    Can't figure out why this ajax request fires two times

  9. 9

    Elasticsearch times out on every search request until restart

  10. 10

    Can't figure out why this ajax request fires two times

  11. 11

    Server request for audio file times out before returning any data

  12. 12

    node-http-proxy POST request times out

  13. 13

    iOS: HTTP POST request times out when setting httpBody property

  14. 14

    Why does a cURL request return a percent sign (%) with every request in ZSH?

  15. 15

    Sleep 3 seconds before sending out next request using CURL

  16. 16

    Why does a cURL request from a PHP file not work, when the same cURL request from the Linux console does?

  17. 17

    Does conn.SetDeadline() close the connection if it times out

  18. 18

    when connection times out using curl or get_file_contents to an API it kills my script

  19. 19

    GET Request works with python 'requests' library, but does not work with curl

  20. 20

    Does CURL GET recipient see the file making the GET request?

  21. 21

    request.META does not contain header passed from curl -H

  22. 22

    Why does a custom curl HEAD request hang for weebly.com?

  23. 23

    elasticsearch-php update returns bad request where curl does not

  24. 24

    Does `curl -v` show the complete HTTP request including the body?

  25. 25

    Looping by replacing the values in a file and then doing curl request for 25 times increasing count by 1000

  26. 26

    curl timeout eight times

  27. 27

    Working out the number of times a (request handler) function has been called in Go

  28. 28

    In Swift, when using dataTaskWithRequest the completionHandler returns a nil NSURLResponse when the request times out

  29. 29

    What is the best way to handle Invalid CSRF token found in the request when session times out in Spring security

HotTag

Archive