0

I am aware that this question has been asked many times one of them would be this and may be this. This is a most matching question but that didn't work anymore, maybe didn't follow it carefully.

Here's My Code:

import json
from turtle import pos
import requests
from bs4 import BeautifulSoup
import gzip
from io import BytesIO, StringIO

url_for_token = "https://api.ticketing.cm.com/seatedapi/v1.0/public/shop/dgpresell?depth=5&language=EN"

default_header = {
    'accept': 'application/json, text/plain, */*',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': '"en-US,en;q=0.9"',
    'origin': 'https://shop.ticketing.cm.com',
    'referer': 'https://shop.ticketing.cm.com/',
    'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
}

session_request = requests.Session()
session_request.headers.update(default_header)
get_tf_data = session_request.get(url_for_token)

And When I print Output with .text

�k-��l��նo﮷}��a��o#WW�]�ZT˕EQ�����k\�|�9�Vs������Qt���?���^�������|8<����������=1�\�p��v۷/���2Q�k#W��
y��������p�iA�]��7�bVOv���'���=�}�N�)U��7�:��A�J�!!v<S��~�y��_��r������gRd���B��Z2j���2�����x�ךWy��h1�n���Y� �T�13������O�Ϋ>��y�F�
�-�+;8Z�������O�<�����ᑏ�G�*o�^��c�w?�����r�r���E�����tB�j�����lW�,����|x6

When I do with .content it comes with this:

b'\x83\xc5\x12\x11U\xb5\x1e\x02\xd0HY8\x7f\xbf\xbf\xbdi\xf5\xf5K\xbd\xdf\x11\tB\xc8B\x9a\xd9\xc3\xe38G\x1f\xb67q\xef\x99\xa9\xae

When I tried to decode:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 0: invalid start byte

Please help me out with .content I guess it is not possible with .text.

Basically What I Want is I found from this

The response is compressed with gzip. With urllib/urllib2 you need to handle this explicitly (whereas a higher level library like requests will decompress automatically)

but the problem is I can't decode

b'\x83

When I try :

strr = str(get_tf_data.content)[2:-1]
print(strr)
buf = StringIO(strr)
f = gzip.GzipFile(fileobj=buf)
print(f.read())

I got this error :

    return self._buffer[read:] + \
TypeError: can't concat str to bytes
Adarsh Raj
  • 325
  • 4
  • 17

1 Answers1

1

You have not completely filled out the header. You need to specify the missing information in accept

import requests

url = "https://api.ticketing.cm.com/seatedapi/v1.0/public/shop/dgpresell?depth=5&language=EN"

headers = {
  'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}

response = requests.request("GET", url, headers=headers)
print(response.text)

OUTPUT:

{"id":"2d15d893-79a6-448b-99f4-95b62a71ea3f","name":"ResellDGP","isPrimary":false,"domain":"https:\/\/shop.ticketing.cm.com\/","slug":"dgpresell","queueId":null,"loginPolicy":"NONE","personalisationPolicy":"AFTER_CHECKOUT","invoicePolicy":"NONE","isDiscountEnabled":false,"isResellEnabled":false,"isSeatMapEnabled":false,"isSeatAllocationEnabled":true,"isAccountCreationEnabled":false,"isSupportLinkEnabled":true,"isDownloadOrderEnabled":false,"isPersonalisationOrderEnabled":false,"isCmHidden":false,"isIbanEnabled":false,"isTicketsPageEnabled":true,"isHideEventDates":false,"isDisplayRingOnly":true,"reservationMinutes":10,"supportUrl":"https:\/\/dutchgp.com\/faq-categorie\/resell\/","successCallbackUrl":null,"fields":{"name":"REQUIRED","email":"REQUIRED","phoneNumber":"REQUIRED","gender":"REQUIRED","street":"REQUIRED","houseNumber":"REQUIRED","postalCode":"REQUIRED","city":"REQUIRED","birthday":"REQUIRED"},"accountLabel":null,"discountLabel":null,"footerLeft":null,"footerMiddle":null,"footerRight":null,"loginIntroduction":null,"capacityDisplay":"DONT_SHOW","capacityDisplayValue":null,"trackers":[{"id":"87bd4202-cd0f-4381-8a06-cc9ac0358f19","type":"GOOGLE_TAG_MANAGER","key":"G-CFLTGN6TS6","data":null,"shopId":"2d15d893-79a6-448b-99f4-95b62a71ea3f"},{"id":"aa722ce6-c63f-4b04-a3c0-ad104ed82140","type":"FACEBOOK_PIXEL","key":"2297184730551182","data":null,"shopId":"2d15d893-79a6-448b-99f4-95b62a71ea3f"},{"id":"e3c7eda3-0027-43f3-a02b-de18f4af389f","type":"GOOGLE_ANALYTICS","key":"UA-139300112-1","data":null,"shopId":"2d15d893-79a6-448b-99f4-95b62a71ea3f"}],"shopPages":[{"id":"2db029be-ab90-4288-ad3f-bb18519be976","shopId":"2d15d893-79a6-448b-99f4-95b62a71ea3f","menuName":null,"pageName":"Buy tickets","description":"<p>Welcome to the official resell platform of the Formula 1 Heineken Dutch Grand Prix 2022. On this platform you can safely buy tickets from other race fans.&nbsp;<\/p><p><br><\/p>","shopEvents":[{"eventId":"cb04e0bd-ea4b-41c2-a485-baa6b3a58c05","event":{"id":"cb04e0bd-ea4b-41c2-a485-baa6b3a58c05","status":"ONLINE","venueId":"12c424fe-b4e6-48e3-a710-5c1785eea8f5","categoryId":"b4176c02-388e-4ae3-b038-2a2d2a4a8695","pricePlanId":"7bcee586-3223-48e9-93e6-b22272b3860f","name":"Dutch Grand Prix Super Friday 2022","description":"<p>Welcome to the official resell platform of the Formula 1 Heineken Dutch Grand Prix 2022. On this platform you can safely buy tickets from other race fans.&nbsp;<\/p><p>Click on the grandstand\/area where tickets are offered and add the desired number of tickets to your shopping cart on the right. After adding the tickets, you have a limited time to checkout the tickets. After completing the order you will receive a confirmation email. It occurs that it ends up in your spam filter. <\/p><p>Around March\/April 2022 you will receive information about personalizing the tickets. You will then receive the tickets digitally in advance of the event. Tickets within one order will automatically be placed next to each other. Tickets from different orders cannot be connected. <\/p>","riskCategory":null,"startAt":"2022-09-02T06:00:00+00:00","endAt":"2022-09-03T05:00:00+00:00","isLoginRequired":false,"inSale":true,"saleStartAt":"2022-01-01T11:00:09+00:00","saleEndAt":null,"isRequestable":false,"initialized":true,"initializeFailed":false,"resources":[],"type":"EVENT","timezone":{"id":"77a4726f-d540-44df-a325-d2f39f02a233","name":"Europe\/Amsterdam","abbreviation":"CET","countryId":"NL"}},"isPinned":false},{"eventId":"944319d8-147b-477e-a5b7-29b82737aa03","event":{"id":"944319d8-147b-477e-a5b7-29b82737aa03","status":"ONLINE","venueId":"12c424fe-b4e6-48e3-a710-5c1785eea8f5","categoryId":"05a39985-31c4-489e-a700-7abededa5c84","pricePlanId":"ecf22bc8-2414-4b4c-8380-fcc889ba4a9d","name":"Dutch Grand Prix Saturday 2022","description":"<p>Click on the grandstand\/area where tickets are offered and add the desired number of tickets to your shopping cart on the right. After adding the tickets, you have a limited time to checkout the tickets. After completing the order you will receive a confirmation email. It occurs that it ends up in your spam filter.&nbsp;<\/p><p>Around June 2022 you will receive information about personalizing the tickets. You will then receive the tickets digitally in advance of the event. Tickets within one order will automatically be placed next to each other11T08:25:40+00:00","updatedAt":"2020-05-11T08:25:40+00:00"},{"id":"ae37edfb-d4c0-42af-b259-2b46dc5b9dbb","settingId":"BLOCKED_CUSTOMER_FIELDS","settingOptionIds":[],"value":["FIRST_NAME","INSERTION","LAST_NAME","EMAIL","PHONE_NUMBER"],"settingOptionId":null,"createdAt":"2020-06-03T10:48:40+00:00","updatedAt":"2020-06-03T10:49:36+00:00"},{"id":"ba875165-e9f2-439a-a32b-867fd56fb2f5","settingId":"SUBSCRIPTION_DISABLED","settingOptionIds":[],"value":true,"settingOptionId":null,"createdAt":"2020-05-08T07:03:28+00:00","updatedAt":"2020-05-08T07:03:28+00:00"},{"id":"3b1866d8-f21f-4435-a6f9-bee27de5031d","settingId":"IGNORE_CONSENT_IDS","settingOptionIds":[],"value":"0010cb15-21d0-40cc-8c6d-e251729ba4a9","settingOptionId":null,"createdAt":"2021-11-01T12:11:54+00:00","updatedAt":"2021-11-01T12:11:54+00:00"}],"languages":["DE","EN","FR","NL"],"customFields":[{"id":"b022ba5f-4d27-46f8-90ff-0363ecb885ec","label":"How will you travel to Zandvoort?","type":"SELECT","scope":"CUSTOMER","isRequired":true,"customFieldOptions":[{"id":"fa0afca4-d930-4733-89aa-0761929ab926","label":"Train","order":"0"},{"id":"7c08d852-e535-4576-83c6-6d8b123520c5","label":"Organised bus transport","order":"1"},{"id":"55cff8c3-6c69-4596-affb-5c37b7f13449","label":"Bicycle","order":"2"},{"id":"b9cc6bcf-d791-4b90-a0aa-e2cc114e84dc","label":"Walking","order":"3"},{"id":"66a756bd-c743-479e-a34a-a0109250077f","label":"I will let you know later","order":"4"}]}],"technicalLinkId":"043503a0-7550-11e9-aaa0-357101939cb2","footer":[{"content":null},{"content":null},{"content":null}]}
Sergey K
  • 1,329
  • 1
  • 7
  • 15