Skip to content

Commit 52090d7

Browse files
author
Peter
committed
Moved from urllib to requests
1 parent fc5af63 commit 52090d7

3 files changed

Lines changed: 11 additions & 19 deletions

File tree

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='slackclient',
4-
version='0.16',
4+
version='0.17',
55
description='Python client for Slack.com',
66
url='http://github.com/slackhq/python-slackclient',
77
author='Ryan Huber',
@@ -10,6 +10,6 @@
1010
packages=['slackclient'],
1111
install_requires=[
1212
'websocket-client',
13-
'future',
13+
'requests',
1414
],
1515
zip_safe=False)

slackclient/_server.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ def __repr__(self):
4141

4242
def rtm_connect(self, reconnect=False):
4343
reply = self.api_requester.do(self.token, "rtm.start")
44-
if reply.code != 200:
44+
if reply.status_code != 200:
4545
raise SlackConnectionError
4646
else:
47-
login_data = json.loads(reply.read().decode('utf-8'))
47+
login_data = reply.json()
4848
if login_data["ok"]:
4949
self.ws_url = login_data['url']
5050
if not reconnect:
@@ -129,11 +129,10 @@ def attach_channel(self, name, id, members=[]):
129129

130130
def join_channel(self, name):
131131
print(self.api_requester.do(self.token,
132-
"channels.join?name={}".format(name)).read())
132+
"channels.join?name={}".format(name)).text)
133133

134134
def api_call(self, method, **kwargs):
135-
reply = self.api_requester.do(self.token, method, kwargs)
136-
return reply.read()
135+
return self.api_requester.do(self.token, method, kwargs).text
137136

138137

139138
class SlackConnectionError(Exception):

slackclient/_slackrequest.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
import time
2-
from future.moves.urllib.parse import urlparse, urlencode
3-
from future.moves.urllib.request import urlopen, Request
4-
from future.moves.urllib.error import HTTPError
1+
import requests
52

63

74
class SlackRequest(object):
8-
def __init__(self):
9-
pass
10-
115
def do(self, token, request="?", post_data={}, domain="slack.com"):
12-
post_data["token"] = token
13-
post_data = urlencode(post_data)
14-
url = 'https://{}/api/{}'.format(domain, request)
15-
return urlopen(url, post_data.encode('utf-8'))
16-
6+
return requests.post(
7+
'https://{0}/api/{1}'.format(domain, request),
8+
data=dict(post_data, token=token),
9+
)

0 commit comments

Comments
 (0)