Python将列表中的值插入URL

Python将列表中的值插入URL,python,python-3.x,Python,Python 3.x,我正在尝试添加一个通过API调用遍历列表的迭代。在每次迭代中,我希望当前条目将其值插入URL。我尝试过使用.format()方法,但似乎不起作用。URl调用,但失败。它应该是这样的:/mailMessages/7928?include。当我打印(标识)时,我得到 代码: for ident in idents: http = urllib3.PoolManager() r = http.request('GET', 'https://api.pipedrive.com/v1/ma

我正在尝试添加一个通过API调用遍历列表的迭代。在每次迭代中,我希望当前条目将其值插入URL。我尝试过使用
.format()
方法,但似乎不起作用。URl调用,但失败。它应该是这样的:/mailMessages/7928?include。当我打印(标识)时,我得到

代码:

for ident in idents:
    http = urllib3.PoolManager()
    r = http.request('GET', 'https://api.pipedrive.com/v1/mailbox/mailMessages/{0}?include_body=1&api_token=TOKEN'.format(ident))
    datas = list()
    mails = json.loads(r.data.decode('utf-8'))
    datas.append(mails)
有人能给我指一下正确的方向吗


提前谢谢。

这可能会有所帮助。您需要将
'datas'
列表置于for循环之外

datas = list()
for ident in idents:
    http = urllib3.PoolManager()
    r = http.request('GET', 'https://api.pipedrive.com/v1/mailbox/mailMessages/{0}?include_body=1&api_token=TOKEN'.format(ident))
    mails = json.loads(r.data.decode('utf-8'))
    datas.append(mails)

什么方式不起作用?抱歉,更新了问题以使其更清楚。谢谢rakesh。做了这些之后,我意识到这是列表的问题。当我打印列表时,我得到了格式['18284'],这就是要插入到URL中的内容,应该插入的只是18284。
datas = list()
for ident in idents:
    http = urllib3.PoolManager()
    r = http.request('GET', 'https://api.pipedrive.com/v1/mailbox/mailMessages/{0}?include_body=1&api_token=TOKEN'.format(ident))
    mails = json.loads(r.data.decode('utf-8'))
    datas.append(mails)