0

I am trying to call a GET request on the following link: https://www.sivasdescalzo.com/en/contact/manage/preferences/hash/aefc79883b2411a6830d5ac265170e32596df603b4c14caae96d2062026a33a8e8c9ee34317d09f3151ebf7c692b4b7945ad48f88853d00c0ee3a550d1e3dc88?deliveryName=DM3985. (which is a redirection URL from https://t1.news.sivasdescalzo.com/r/?id=h8e98f70,2d60df8,2d6f801&e=cDE9YWVmYzc5ODgzYjI0MTFhNjgzMGQ1YWMyNjUxNzBlMzI1OTZkZjYwM2I0YzE0Y2FhZTk2ZDIwNjIwMjZhMzNhOGU4YzllZTM0MzE3ZDA5ZjMxNTFlYmY3YzY5MmI0Yjc5NDVhZDQ4Zjg4ODUzZDAwYzBlZTNhNTUwZDFlM2RjODg&s=U6qS6rMRcR1sEYc9fIjnVzpik-_HeCeD6qxCJd7Xfug)

However, I only get error 405 - method not allowed.

I have also opened the second link manually, got redirected to the first link and have checked the https traffic with Proxyman (Screenshot). I am sending the same parameters which I sent manually. My code snippet:

link = "https://t1.news.sivasdescalzo.com/r/?id=h8e98f70,2d60df8,2d6f801&e=cDE9YWVmYzc5ODgzYjI0MTFhNjgzMGQ1YWMyNjUxNzBlMzI1OTZkZjYwM2I0YzE0Y2FhZTk2ZDIwNjIwMjZhMzNhOGU4YzllZTM0MzE3ZDA5ZjMxNTFlYmY3YzY5MmI0Yjc5NDVhZDQ4Zjg4ODUzZDAwYzBlZTNhNTUwZDFlM2RjODg&s=U6qS6rMRcR1sEYc9fIjnVzpik-_HeCeD6qxCJd7Xfug"[enter image description here](https://i.stack.imgur.com/ockpE.png)
headers = {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
        "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.7",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "de-DE,de;q=0.9"
}

# Retrieve redirection URL and cookies 
response = requests.head(link, headers=headers)
new_url = response.headers["Location"]
cookies = "; ".join(f"{key}={response.cookies[key]}" for key in response.cookies.keys())

headers["Cookie"] = cookies


response = requests.get(new_url, headers=headers)

What would be the best way to get around this? How would I go about debugging my issue?

I have tried .head and tried checking for allowed methods:

r = requests.options(new_url)
allow = r.headers.get("Allow", "allow not found")
print(allow)

Both didn't help.

I would highly appreciate if anyone could help me with this one! Ideally tell me how I would go along debugging the issue and not just the solution. Thanks in advance!

Peter
  • 9
  • 2
  • @SalmanA No sorry, accidentally didn't paste a small part. The head request works completely fine, its the get request at the very last line of the first code snippet – Peter May 16 '23 at 13:56

0 Answers0