Merge pull request #124 from leezu/patch-1

Update Python example for Python 3
This commit is contained in:
Alex Yatskov 2019-09-22 10:05:06 -07:00 committed by GitHub
commit f2e0ac93b5
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: