Vor Kurzem aufgerufene Suchen


Keine vor kurzem aufgerufene Suchen

HTTP Error 503 Incremental tickets API



Gepostet 25. Juli 2022

Im using the incremental tickets API to get all the tickets in my companies account and upload it to a S3 bucket, sometimes the script runs just fine and im able to get 4-5 files with 1000 tickets each, but sometimes it will randomly throw me a 503 error with no retry-after message, while also being very far from reaching API rate limit.

The user_agent_list was used to spoof the user_agent header to test if i would still get the 503 error, it seemed to increase the amount of times the while loop would run without receiving an error, but still didn't fix it.

session = boto3.Session(

  aws_access_key_id={ACCESS KEY},

  aws_secret_access_key={SECRET KEY}

)

def upload_to_s3(data):

  bucket_name = "BUCKET"

    file_name = f"Tickets/{datetime.today()}-dump.json"

    s3 = session.resource("s3")

    object = s3.Object(bucket_name, file_name)

    result = object.put(Body=data)

    return

user_agent_list = [

    'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0',

    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36',

    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'

]

user_agent = random.choice(user_agent_list)

url = 'https://{DOMAIN}.zendesk.com/api/v2/incremental/tickets/cursor.json?start_time=1641006000&include=slas'

user = {email} + '/token'

pwd = {password}

headers = {

    'User-Agent': {user_agent}}

response = requests.get(url, headers, auth=(user, pwd))

print(response.headers)

print(user_agent)

if response.status_code != 200:

    print('Status:', response.status_code,

          'Problem with the request. Exiting.')

    response.reason

    response.raise_for_status()

    exit()

else:

    print(response.status_code)

data = response.json()

data1 = json.dumps(response.json(), indent=4, ensure_ascii=False)

upload_to_s3(data1)

EOS = data["end_of_stream"]

while EOS != 'true':

    user_agent = random.choice(user_agent_list)

    EOS = data["end_of_stream"]

    new_url = data["after_url"]

    response = requests.get(new_url, headers, auth=(user, pwd))

    print(user_agent)

    print(response.headers)

    if response.status_code != 200:

        print('Status:', response.status_code,

              'Problem with the request. Exiting.')

        response.reason

        response.raise_for_status()

        exit()

    else:

        print(response.status_code)

  data = response.json()

    data1 = json.dumps(response.json(), indent=4, ensure_ascii=False)

    upload_to_s3(data1)

    time.sleep(10)

0

1

1 Kommentar

Hello,

Is there any solution to that? I am getting 504 or upstream request timeout error using /api/v2/incremental/tickets/cursor.json?start_time=1675271346&include=slas so incremental ticket load with sla as sideload. It works when i pick more recent start_time.

What can be the problem?

 

1


Anmelden, um einen Kommentar zu hinterlassen.

Sie finden nicht, wonach Sie suchen?

Neuer Post