I am trying to run webhooks on FME Server. The webhooks run successfully and I get status code 200 from the server but when I check the length of the data in the response it is 0, in this case 0. Is there a header I am missing?
from urllib.request import urlopen
from shutil import copyfileobj
def runwebhook(runurl):
response = urlopen(runurl)
if response.getcode()==200:
print("Success")
return response
def savefilestream(filepath,response):
if exists(filepath): remove(filepath)
if isinstance(response.read(),bytes)==True:
with open(filepath,'wb') as f:
data = len(response.read())
print(data)
copyfileobj(response, f)
f.close()
print("File Saved Successfully")
else:
with open(filepath,'w') as f:
f.write(str(response.read()))
f.close()
print("File Saved as text")
def runwebhookwithheaders(runurl,hooktoken):
runresponse = None
headers = {
'Authorization':f"fmetoken token={hooktoken}",
'Accept': 'application/octet-stream',
'Content-Type': "application/octet-stream",
'accept-encoding': "gzip, deflate",
'Content-Transfer-Encoding': 'binary',
'Connection': "keep-alive"
}
req = Request(self.runurl,headers=headers)
try:
runresponse = urlopen(req)
except HTTPError as e:
print(e.code)
print(e.code)
except URLError as e:
print(e.reason)
print(e.reason)
return runresponse
#example usage for a simple webhook
filepath= r":\filepath\\"
runurl = "%%Webhookurl%%"
resp = runwebhook(runurl)
savefilestream(filepath,resp)
# example with token
filepath= r":\filepath\\"
runurl = "%%Webhookurl%%"
hooktoken = "token"
resp = runwebhookewithheaders(runurl,token)
savefilestream(filepath,resp)