-
-
Save Josebuendia/77d0810c99450cce165ce27f8f3c08e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import urlencode | |
import requests | |
from time import sleep | |
import time | |
from requests.adapters import HTTPAdapter | |
from requests.packages.urllib3.util.retry import Retry | |
from requests.packages.urllib3.util.ssl_ import create_urllib3_context | |
import ssl | |
from urllib3.poolmanager import PoolManager | |
from requests.adapters import HTTPAdapter | |
#### | |
# new code to solve handshake failure | |
class Ssl3HttpAdapter(HTTPAdapter): | |
""""Transport adapter" that allows us to use SSLv3.""" | |
def init_poolmanager(self, connections, maxsize, block=False): | |
self.poolmanager = PoolManager( | |
num_pools=connections, maxsize=maxsize, | |
block=block, ssl_version=ssl.PROTOCOL_SSLv3) | |
credentials = '********', '********!' | |
session = requests.Session() | |
session.auth = credentials | |
params = { | |
'query': 'type:ticket status:open', | |
'sort_by': 'created_at', | |
'sort_order': 'asc', | |
'page[size]': 25 | |
} | |
# url = 'https://wow5746.zendesk.com/api/v2/search.json?' + urlencode(params) | |
#### | |
# "users": [ ... ], | |
# "meta": { | |
# "has_more": true, | |
# "after_cursor": "eyJvIjoibmljZV9pZCIsInYiOiJhV2tCQUFBQUFBQUEifQ==", | |
# "before_cursor": "eyJvIjoibmljZV9pZCIsInYiOiJhUzRCQUFBQUFBQUEifQ==" | |
# }, | |
# | |
# "links": { | |
# "next": "https://example.zendesk.com/api/v2/users.json?page[size]=100&page[after]=eyJvIjoibmljZV9pZCIsInYiOiJhV2tCQUFBQUFBQUEifQ==", | |
# "prev": "https://example.zendesk.com/api/v2/users.json?page[size]=100&page[before]=eyJvIjoibmljZV9pZCIsInYiOiJhUzRCQUFBQUFBQUEifQ==" | |
# } | |
# | |
# #### | |
url = 'https://wow5746.zendesk.com/api/v2/tickets.json?page[size]=25' + urlencode(params) | |
## | |
while url: | |
response = session.get(url) | |
# response = requests.get(url) | |
if response.status_code != 200: | |
# print('Status:', response.status_code, 'Problem with the request. Exiting.') | |
print('Status:', response.status_code, ' Problem with the request. Response was:', response.text, ' Exiting.') | |
exit() | |
# Print the subject of each ticket in the results | |
data = response.json() | |
for ticket in data['tickets']: | |
print(ticket) | |
# print(result['subject']) | |
# time.sleep(5) | |
if data['meta']['has_more']: | |
url = data['links']['next'] | |
else: | |
url = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment