Yandex Disk api image link gets 403 error when the image is added from javascript

251 Views Asked by At

I have a python script that uploads images to Yandex Disk using the yadisk module. The script looks like this:

def uploadYandexDisk(path, filename):
   try:
        y.upload(filename, path)
        y.publish(path) # I don't know if this is necessary
        return y.get_download_link(path)
    except Exception as e:
        print(e)
        return None

I get a link that looks similar to this: https://downloader.disk.yandex.ru/disk/bfa79f689c05d8baadcf95f4d3ed8fbb29c6cfa9f6e0204a27bfe58bf4ecf1b4/63c85be8/dxysKH9-IRe0fopHnDA9GGf54mxrEpFtdH4pyMm2uqkUclp7t5xT1rW_NQ-wSsohWwsfbUVUDT5YqkHthwEj4g%3D%3D?uid=1070951606&filename=apple-xxhkw-caquk.png&disposition=attachment&hash=&limit=0&content_type=image%2Fpng&owner_uid=1070951606&fsize=675526&hid=a49cfeb39e5819728ee8221f113b4fbd&media_type=image&tknv=v2&etag=0eb79b7987ca12d70612a2c581c6239d

When I open the link in my browser and even in incognito mode where I'm not logged in to Yandex, it works. And it also works when I directly put the link in the html without any javascript. But when I try to put the link in the src of an img using javascript I get a 403 not authorized error in the console. Is there a way to fix this or any workarounds?

0

There are 0 best solutions below