这个方法returns是url吗?

Does this method returns a url?

抱歉,我正在学习,如果这是一个愚蠢的问题,请原谅我。 我得到了这个方法(更新):

    def get_photo(self, photo_reference):
    print(self.photourl)
    print(photo_reference)
    resp = requests.get(
        url='{}{}'.format(self.photourl, photo_reference),
        params={'key': self.api_key}
    )
    try:
        return resp.json()
    except ValueError:
        print('Invalid JSON')

我用 Google Places API - Place Photo 构建了 requests.get。 在我的 __init__(self):

self.place_detail_url = 'https://maps.googleapis.com/maps/api/place/'
self.ref = 'photo?maxwidth=200&photoreference='
self.photourl = self.place_detail_url + self.ref

我想从 google 地点 API 获取照片,但我试过了 returns None。 我想知道 get_photo 方法 returns 是什么,如果它不是 url。如何将其编码为 url?

也许可以试试这个(基于你似乎更喜欢自己构建 URL 的方法):

def get_photo(self, photo_reference):
    request_url = (self.place_detail_url + self.ref + photo_reference + '&key=' + self.api_key)
    output_file = (/path/to/image/here/file.png)
    with open(output_file, 'wb') as output:
        output.write(requests.get(request_url).content)

我得到了答案,resp 是一个对象,根据 HTTP 状态 200,我的 URL 是好的。所以我只需要做 return resp.url 就可以得到正确的 URL link。这是一个小问题,但我把它弄大了。抱歉并感谢您的所有回答!