Home > front end >  Getting a string from JSON response and adding 1 to it
Getting a string from JSON response and adding 1 to it

Time:02-08

I have a RESTful GET request from a ticketing system. It gets the most recent ticket number entered in the system, and prints it for the user. What I need to do is then take the number it gives, and add one to it for a POST request. For example, here's my code:

response = requests.get(url=url, headers=headers)
    data2 = response.json()
    ntickId = data2[0]['id']
    if tickId < ntickId:
        pprint(f"The most recent ticket is: {ntickId}. Press any key to continue.")
        input(" ")
        pprint(f"Your new ticket number will be: "   int({ntickId}) 1)

Earlier, I entered the number 468516. Here's my output:

Please Enter Event Ticket ID: 468516
'The most recent ticket is: 468999. Press any key to continue.

So far so good. So, ideally I'd expect 469000 to be the new ticket number. Here's what I got instead:

pprint(f"Your new ticket number will be: "   int({ntickId}) 1)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'set'

I'm not sure how to go about this.

CodePudding user response:

It should be:

pprint(f"Your new ticket number will be: {int(ntickId) 1}")

Note, given that you compare tickId and ntickId conversion to int is most likely not necessary because ntickId is already an int. You may edit your question to include sample JSON response from the API. In this case:

pprint(f"Your new ticket number will be: {ntickId 1}")
  •  Tags:  
  • Related