From 34049299e692f1fb55c6240e1c21601c3cafa114 Mon Sep 17 00:00:00 2001 From: Leonard Lausen Date: Sun, 22 Sep 2019 10:28:25 +0000 Subject: [PATCH] Update Python example for Python 3 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6d49853..74a3fa4 100644 --- a/README.md +++ b/README.md @@ -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: