对不起,如果这是一个愚蠢的问题,我正在学习如此原谅我。 我得到这个方法(更新):此方法是否返回一个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')
我建立了requests.get与Google Places API - Place Photo。 在我__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
我想从谷歌的地方API的照片,但我想,它返回None。 我不知道get_photo
方法返回什么,如果它不是一个网址。我怎样才能将它编码到一个网址?
你应该从'get_photo()'返回一些东西吗?.. – alecxe
该方法里没有'return'语句,所以它会返回默认的'None'。我怀疑你应该分配'requests.get'调用返回的值并返回它,它应该是一个包含你想要的照片数据的对象(它也包含其他有用的东西)。 –
你想下载图片吗? requests.get(url).content您需要将其与一个打开的命令组合在一起以保存文件:'open(file,'wb')as file:file.write(requests.get(url).content) ' – Lost