2

Is there a python equivalent for checking if a host accepts the trace method?

curl -sIX TRACE neopets.com

Note, I'm not trying to get a request traceback, I'm also not trying to get my raw request. I'm trying to verify if a webserver supports the TRACE method.

https://curl.trillworks.com/ translates the command to:

requests.head('http://neopets.com') but it doesn't seem to get me the same result as the curl.

EDIT: I guess I have to construct the request

req = requests.Request('TRACE', 'https://google.com')
r = req.prepare()
s = requests.Session()
s.send(r)
Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144

1 Answers1

1

Since you just want to check if the TRACE method is accepted, you can use the OPTIONS method instead. The available methods will be returned in the Allow header.

import requests

response = requests.options('http://google.com/')
print(response.headers['Allow'])

>> GET, HEAD

isopach
  • 1,783
  • 7
  • 31
  • 43
  • While this would generally work for most sites, it seems like for some this wouldn't, I tried it with http://neopets.com and it doesn't seem like the response header contains an Allow attribute – Stupid.Fat.Cat Feb 21 '20 at 17:27