Regarding Permission denied when loading images

Asked 2 years ago, Updated 2 years ago, 104 views

I'm a python beginner.
I created the following .py to tweet the image.

#!/usr/bin/env python
# coding —utf-8

import json
from requests_oauthlib import OAuth1 Session

CK='#ConsumerKey'#ConsumerKey
CS='#ConsumerSecret'#ConsumerSecret
AT='#AccessToken'#AccessToken
AS='#AccessToken'#AccessTokenSecert

# Image and Text URL
url_media="https://upload.twitter.com/1.1/media/upload.json"
url_text="https://api.twitter.com/1.1/statuses/update.json"

# authentication
twitter = OAuth1 Session (CK, CS, AT, AS)

# image posting
path = "# Path to image file" # Path to image file
files={"media":open(path, 'rb')}
req_media=twitter.post(url_media, files=files)

# Review Response
if req_media.status_code!=200:
 print("Upload image is Failed:%s", req_media.text)
exit()

# Get ID
media_id=json.loads(req_media.text) ['media_id']
print("Media ID: %d"%media_id)

# Post text with ID
param={'status':'#splatoon2#NintendoSwitch', "media_ids": [media_id]}
req_media=twitter.post(url_text, params=params)

# Review Response
if req_media.status_code!=200:
 print("Upload text is Failed:%s", req_text.text)
exit()

print("OK")

If you do the above, you will receive the following error:
C Drive - There is an image folder under the desktop and it is not read-only, but I don't know what to do.
I would appreciate it if you could let me know.

Traceback (most recent call last):
  File "imagetweet.py", line 21, in <module>
    files={"media":open(path, 'rb')}
PermissionError: [Errno13] Permission denied: '# Image File Path'

python windows twitter

2022-09-30 15:03

1 Answers

Is the user running Python not given the appropriate permission?

Right-click an image file, select Properties, and click the Security tab to see the status of your permissions to the image file.


2022-09-30 15:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.