Skip to content

Commit

Permalink
Fix urlopen in Python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
eliangcs committed Mar 28, 2017
1 parent 91417ed commit aceabbd
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions http_prompt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,17 @@ def cli(spec, url, http_options):
os.environ['LESS'] = '-RXF'

if spec:
with urlopen(spec) as f:
content = f.read().decode('utf-8')
f = urlopen(spec)
try:
spec = json.loads(content)
except json.JSONDecodeError:
click.secho("Warning: Specification file '%s' is not JSON" %
spec, err=True, fg='red')
spec = None
content = f.read().decode('utf-8')
try:
spec = json.loads(content)
except json.JSONDecodeError:
click.secho("Warning: Specification file '%s' is not JSON" %
spec, err=True, fg='red')
spec = None
finally:
f.close()

url = fix_incomplete_url(url)
context = Context(url, spec=spec)
Expand Down

0 comments on commit aceabbd

Please sign in to comment.