Update Python example for Python 3

This commit is contained in:
Leonard Lausen 2019-09-22 10:28:25 +00:00 committed by GitHub
parent 64319e1246
commit 34049299e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -104,14 +104,14 @@ curl localhost:8765 -X POST -d "{\"action\": \"deckNames\", \"version\": 6}"
```python
import json
import urllib2
import urllib.request
def request(action, **params):
return {'action': action, 'params': params, 'version': 6}
def invoke(action, **params):
requestJson = json.dumps(request(action, **params))
response = json.load(urllib2.urlopen(urllib2.Request('http://localhost:8765', requestJson)))
requestJson = json.dumps(request(action, **params)).encode('utf-8')
response = json.load(urllib.request.urlopen(urllib.request.Request('http://localhost:8765', requestJson)))
if len(response) != 2:
raise Exception('response has an unexpected number of fields')
if 'error' not in response: