Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make request module compatible with python3 #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions eventsource/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import argparse
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to (at least) add from __future__ import print_function. I'd add as well unicode_literals.


import json
import urllib2

# urllib is tricky, maybe use Requests?
from future.standard_library import install_aliases
install_aliases()
import urllib.parse, urllib.request, urllib.error

def send_json(url, data):
"""
Expand Down Expand Up @@ -75,12 +79,12 @@ def start():

try:
if args.json:
print send_json("http://%(host)s:%(port)s/%(action)s/%(token)s" % args.__dict__, args.data)
print(send_json("http://%(host)s:%(port)s/%(action)s/%(token)s" % args.__dict__, args.data))
else:
print send_string("http://%(host)s:%(port)s/%(action)s/%(token)s" % args.__dict__, args.data)
print(send_string("http://%(host)s:%(port)s/%(action)s/%(token)s" % args.__dict__, args.data))
sys.exit(0)
except Exception, err:
print "Unable to send request (%s): %s" % (err, err.readline().split("<body>")[-1].split("</body>")[0])
except Exception as err:
print("Unable to send request (%s): %s" % (err, err.readline().split("<body>")[-1].split("</body>")[0]))
sys.exit(1)

if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def read(*names):
install_requires = [
'tornado>=4.4',
'pycurl',
] + (['future'] if sys.version_info.major == 2 else []),
'future',
],
packages = find_packages(exclude=['examples', 'tests']),
url='http://packages.python.org/eventsource/',
include_package_data=True,
Expand Down