I am working on an email scraper and it appears to be throwing an error when trying to save the files from the email attachments. Any ideas would be much appreciated!
This is the part of the code where the error occurs:
for part in email_message.walk():
print("starting for part")
print(part.get_payload())
if part.get_content_maintype() == 'multipart' or part.get_content_maintype() == 'text':
print("multipart selected")
if part.get('Content-Disposition') is None or part.get('Content-Disposition') is 'inline':
print("content disposition is none or inline")
fileName = part.get_filename()
print("filename: ", str(fileName))
if bool(fileName):
print("valid filename")
filePath = os.path.join('/bm_data/ownCloud/BuildMapper/acquireddata/', fileName)
if not os.path.isfile(filePath):
print("os path is file is not")
fp = open(filePath, 'wb')
fp.write(part.get_payload(decode=True))
fp.close()
s3.meta.client.upload_file(filePath, S3_BUCKET, "newfilename")
and this is the error message:
Traceback (most recent call last): File "emailscraper2020aug11.py", line 74, in <module>
if not os.path.isfile(filePath): NameError: name 'filePath' is not defined