-1

I'm developing a Twitch chat bot in Python. However, I'm having some trouble with a feature that has been requested a lot. I need to pull the "gameserverid" and "gameextrainfo" data from a JSON file. example file

import urllib2
import json
req = urllib2.Request("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=605C90955CFDE6B1CB7D2EFF5FE824A0&steamids=76561198022404556")
opener = urllib2.build_opener()
f = opener.open(req)
json = json.loads(f.read())
currentlyPlaying = json[gameextrainfo]
gameServer = json[gameserverid]

This is the code I've got at the moment. I want to get it so that other commands can print the variables "currentlyPlaying" and "gameServer" to the IRC chat. However, when I do this, I get this in the console :

Traceback (most recent call last):
  File "N:/_DEVELOPMENT/Atlassian Cloud/TwitchChatBot/Testing/grabplayerinfofromsteam.py", line 1, in <module>
    import urllib2
ImportError: No module named 'urllib2'

Any ideas? I'm in a Windows environment, running on the latest version of Python (Python 3.5.1)

1 Answers1

2
try:
    import urllib.request as urllib2
except ImportError:
    import urllib2

but dont use urllib2, use requests!

pip install requests 

http://docs.python-requests.org/en/master/

Merlin
  • 24,552
  • 41
  • 131
  • 206