ValvePython / steam

☁️ Python package for interacting with Steam
http://steam.readthedocs.io
MIT License
1.11k stars 147 forks source link

curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused #176

Closed woctezuma closed 5 years ago

woctezuma commented 5 years ago

Hello,

I am trying to run recipe n°2 SimpleWebAPI.

I have edited run_webapi.py as suggested in #97, by adding these two lines at the top of the file.

import gevent.monkey
gevent.monkey.patch_all()  # Reference: https://github.com/gevent/gevent/issues/1235

I hve also edited the following import for Python 3:

from gevent.pywsgi import WSGIServer  # Reference: https://stackoverflow.com/a/50465220

After I run python run_webapi.py, input my username, password and 2FA code, the following is displayed:

2019-02-01 13:52:32,182 | Steam Worker | Connected to ('[redacted]', 27017)
2019-02-01 13:52:32,604 | Steam Worker | ------------------------------
2019-02-01 13:52:32,604 | SimpleWebAPI | Starting HTTP server...
2019-02-01 13:52:34,135 | Steam Worker | Logged on as: Woctezuma
2019-02-01 13:52:34,135 | Steam Worker | Community profile: https://steamcommunity.com/profiles/[redacted]
2019-02-01 13:52:34,135 | Steam Worker | Last logon: 2019-02-01 12:52:32
2019-02-01 13:52:34,135 | Steam Worker | Last logoff: 2019-02-01 12:52:13
2019-02-01 13:52:34,135 | Steam Worker | ------------------------------

Then I try to run the following in a terminal, as suggested in the README:

curl -s 127.0.0.1:5000/ISteamApps/GetProductChanges/?since_changenumber=2397700 | head -10

However, I encounter the following error:

curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
woctezuma commented 5 years ago

The curl command works after I have replaced this part of the code:

    LOG.info("Starting HTTP server...")
    http_server = WSGIServer(('', 5000), app)

    try:
        http_server.serve_forever()
    except KeyboardInterrupt:
        LOG.info("Exit requested")
        worker.close()

with:

    LOG.info("Starting HTTP server...")

    try:
        app.run(host='0.0.0.0')  # Reference: https://stackoverflow.com/a/30554831
    except KeyboardInterrupt:
        LOG.info("Exit requested")
        worker.close()

In which case, it is not required to import WSGIServer anymore.

woctezuma commented 5 years ago

However, the output differs from the output shown in the README:

  1. I don't know why there is a 500 Internal Server Error.
(venv) C:\Users\Woctezuma\PycharmProjects\SimpleWebAPI>curl -s 127.0.0.1:5000/ISteamApps/GetProductInfo/?appids=570,730
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>
  1. For this output, it is just that the change number is too old.
(venv) C:\Users\Woctezuma\PycharmProjects\SimpleWebAPI>curl -s 127.0.0.1:5000/ISteamApps/GetProductChanges/?since_changenumber=2397700
{"current_change_number":5755420,"force_full_app_update":true,"force_full_package_update":true,"since_change_number":2397700}

With a more recent change number, it is fine.

(venv) C:\Users\Woctezuma\PycharmProjects\SimpleWebAPI>curl -s 127.0.0.1:5000/ISteamApps/GetProductChanges/?since_changenumber=5755420
{"app_changes":[{"appid":800000,"change_number":5755444,"needs_token":true},{"appid":1015480,"change_number":5755443,"needs_token":true},{"appid":362620,"change_number":5755442},{"appid":301000,"change_number":5755441,"needs_token":true},{"appid":512470,"change_number
":5755440},{"appid":349110,"change_number":5755439},{"appid":809470,"change_number":5755438},{"appid":367970,"change_number":5755437},{"appid":743320,"change_number":5755436,"needs_token":true},{"appid":690640,"change_number":5755435,"needs_token":true},{"appid":80914
0,"change_number":5755434},{"appid":962290,"change_number":5755433,"needs_token":true},{"appid":966430,"change_number":5755432,"needs_token":true},{"appid":988430,"change_number":5755431},{"appid":648800,"change_number":5755430},{"appid":648350,"change_number":5755429
},{"appid":333950,"change_number":5755428},{"appid":1024860,"change_number":5755427,"needs_token":true},{"appid":941460,"change_number":5755426,"needs_token":true},{"appid":447700,"change_number":5755423,"needs_token":true},{"appid":1008040,"change_number":5755421}],"
current_change_number":5755444,"package_changes":[{"change_number":5755425,"packageid":341148},{"change_number":5755424,"packageid":341147}],"since_change_number":5755420}
  1. This output is fine.
    (venv) C:\Users\Woctezuma\PycharmProjects\SimpleWebAPI>curl 127.0.0.1:5000/ISteamApps/GetPlayerCount/?appid=0
    {"eresult":1,"player_count":14634045}
rossengeorgiev commented 5 years ago

The recipe is from 2 years ago, and some things have changed. I've pushed an update for the code, it should work now.