这是我的代码,它工作得很好,但我如何才能使它有一个新的变量,等于GIF的图像URL,以便用户可以获得GIF的源URL?
import requests
url = "https://giphy.p.rapidapi.com/v1/gifs/search"
searchtag = input()
querystring = {"api_key":"secret_key","q":searchtag,"limit":"1","offset":"0","rating":"pg-13"}
headers = {
'x-rapidapi-key': "4005b98f9bmsh977c629b89034a7p19b52fjsn22b7fb5ce3bb",
'x-rapidapi-host': "giphy.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
发布于 2021-08-04 19:04:49
首先,为了您的个人安全,您可能应该删除您的api密钥。我建议查看用于存储不属于数据库的私有信息的环境文件。第二,回答你的问题,如果你愿意的话,你可以把url声明为一个变量,在这里:
import requests
url = "https://giphy.p.rapidapi.com/v1/gifs/search"
searchtag = input()
querystring = {"api_key":process.env.APIKEY,"q":searchtag,"limit":"1","offset":"0","rating":"pg-13"}
headers = {
'x-rapidapi-key': "4005b98f9bmsh977c629b89034a7p19b52fjsn22b7fb5ce3bb",
'x-rapidapi-host': "giphy.p.rapidapi.com"
}
response = requests.request("GET", url, headers=headers, params=querystring)
gifurl = response.text
print(gifurl)
https://stackoverflow.com/questions/68660047
复制相似问题