如何保留原始字符串(作为变量),以便将其传递给函数?

2024-10-05 10:13:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是firebase,它存储带有特殊字符的图像,比如sohttps://storage.googleapis.com/download/storage/v1/b/myapp.appspot.com/o/images%2F2021%2F5%2F600_jpgimage_5.jpg?generation=1620831628595831&alt=media

但是我想通过img = Image.open(requests.get(imageURL, stream=True).raw)等将此图像传递给枕头来执行一些功能

但是当我记录正在传递的字符串时,它被转换为https://storage.googleapis.com/download/storage/v1/b/myapp.appspot.com/o/images/2021/5/600_jpgimage_5.jpg?generation=1620831628595831

我尝试过这样做rawStringURL = r'%s' %request_args["url"](这个URL在使用Flask的Google云函数中作为参数传递)

我如何保存这个URL,以便在枕头中对其执行操作时,它可以正常工作?我应该先把它下载到a/temp文件夹吗

我对Python非常陌生,大部分应用程序都是用JavaScript编写的


Tags: 图像comurldownloadstoragemyappgenerationjpg
1条回答
网友
1楼 · 发布于 2024-10-05 10:13:00

这就是我解决问题的方法——仍然需要测试,但目前正在努力

import urllib.parse

url = request_args["URL"] #request being received by the Google Cloud Function (Flask)

    url = request_args["url"]
    url_first_half = url[0:89]
    url_second_half = url[89:]
    split_url = url_second_half.split("?")
    url_to_encode = split_url[0]
    url_end = split_url[1]]
    encoded_url_middle = urllib.parse.quote(
        url_to_encode, safe='%20', encoding=None, errors=None)
    correct_url = url_first_half + encoded_url_middle + "?" + url_end + "&alt=media"

相关问题 更多 >

    热门问题