Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
push = _jpush.create_push()
push.audience = jpush.audience(
jpush.tag("tag1", "tag2"),
jpush.alias("alias1", "alias2")
)
push.notification = jpush.notification(alert="Hello world with audience!")
push.platform = jpush.all_
try:
response = push.send()
print response.status_code
self.assertEqual(response.status_code, 200)
except common.Unauthorized, e:
self.assertFalse(isinstance(e, common.Unauthorized))
raise common.Unauthorized("Unauthorized")
except common.APIConnectionException, e:
self.assertFalse(isinstance(e, common.APIConnectionException))
raise common.APIConnectionException("conn")
except common.JPushFailure, e:
self.assertFalse(isinstance(e, common.JPushFailure))
print "JPushFailure"
except:
self.assertFalse(1)
print "Exception"
push.audience = jpush.audience(
jpush.tag("tag1", "tag2"),
jpush.alias("alias1", "alias2")
)
push.notification = jpush.notification(alert="Hello world with audience!")
push.platform = jpush.all_
try:
response = push.send()
print response.status_code
self.assertEqual(response.status_code, 200)
except common.Unauthorized, e:
self.assertFalse(isinstance(e, common.Unauthorized))
raise common.Unauthorized("Unauthorized")
except common.APIConnectionException, e:
self.assertFalse(isinstance(e, common.APIConnectionException))
raise common.APIConnectionException("conn")
except common.JPushFailure, e:
self.assertFalse(isinstance(e, common.JPushFailure))
print "JPushFailure"
except:
self.assertFalse(1)
print "Exception"
def test_push(self):
_jpush = jpush.JPush(app_key, master_secret)
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="hello python jpush api")
push.platform = jpush.all_
try:
response = push.send()
print response.status_code
self.assertEqual(response.status_code, 200)
except common.Unauthorized, e:
self.assertFalse(isinstance(e, common.Unauthorized))
raise common.Unauthorized("Unauthorized")
except common.APIConnectionException, e:
self.assertFalse(isinstance(e, common.APIConnectionException))
raise common.APIConnectionException("conn")
except common.JPushFailure, e:
self.assertFalse(isinstance(e, common.JPushFailure))
print "JPushFailure"
except:
self.assertFalse(1)
print "Exception"
def test_push(self):
_jpush = jpush.JPush(app_key, master_secret)
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="hello python jpush api")
push.platform = jpush.all_
try:
response = push.send()
print response.status_code
self.assertEqual(response.status_code, 200)
except common.Unauthorized, e:
self.assertFalse(isinstance(e, common.Unauthorized))
raise common.Unauthorized("Unauthorized")
except common.APIConnectionException, e:
self.assertFalse(isinstance(e, common.APIConnectionException))
raise common.APIConnectionException("conn")
except common.JPushFailure, e:
self.assertFalse(isinstance(e, common.JPushFailure))
print "JPushFailure"
except:
self.assertFalse(1)
print "Exception"
def test_push(self):
_jpush = jpush.JPush(app_key, master_secret)
push = _jpush.create_push()
push.audience = jpush.all_
push.notification = jpush.notification(alert="hello python jpush api")
push.platform = jpush.all_
try:
response = push.send()
print response.status_code
self.assertEqual(response.status_code, 200)
except common.Unauthorized, e:
self.assertFalse(isinstance(e, common.Unauthorized))
raise common.Unauthorized("Unauthorized")
except common.APIConnectionException, e:
self.assertFalse(isinstance(e, common.APIConnectionException))
raise common.APIConnectionException("conn")
except common.JPushFailure, e:
self.assertFalse(isinstance(e, common.JPushFailure))
print "JPushFailure"
except:
self.assertFalse(1)
print "Exception"
push = _jpush.create_push()
push.audience = jpush.audience(
jpush.tag("tag1", "tag2"),
jpush.alias("alias1", "alias2")
)
push.notification = jpush.notification(alert="Hello world with audience!")
push.platform = jpush.all_
try:
response = push.send()
print response.status_code
self.assertEqual(response.status_code, 200)
except common.Unauthorized, e:
self.assertFalse(isinstance(e, common.Unauthorized))
raise common.Unauthorized("Unauthorized")
except common.APIConnectionException, e:
self.assertFalse(isinstance(e, common.APIConnectionException))
raise common.APIConnectionException("conn")
except common.JPushFailure, e:
self.assertFalse(isinstance(e, common.JPushFailure))
print "JPushFailure"
except:
self.assertFalse(1)
print "Exception"
def _request(self, method, body, url, content_type=None, version=None, params=None):
headers = {}
headers['user-agent'] = 'jpush-api-python-client'
headers['connection'] = 'keep-alive'
headers['content-type'] = 'application/json;charset:utf-8'
logger.debug("Making %s request to %s. Headers:\n\t%s\nBody:\n\t%s",
method, url, '\n\t'.join('%s: %s' % (key, value) for (key, value) in headers.items()), body)
try:
response = self.session.request(method, url, data=body, params=params,
headers=headers, timeout=self.timeout)
except requests.exceptions.ConnectTimeout:
raise common.APIConnectionException("Connection to api.jpush.cn timed out.")
except Exception:
raise common.APIRequestException("Connection to api.jpush.cn error.")
logger.debug("Received %s response. Headers:\n\t%s\nBody:\n\t%s", response.status_code, '\n\t'.join(
'%s: %s' % (key, value) for (key, value) in response.headers.items()), response.content)
if response.status_code == 401:
raise common.Unauthorized("Please check your AppKey and Master Secret")
elif not (200 <= response.status_code < 300):
raise common.JPushFailure.from_response(response)
return response