Jupyter 取代了 '&'通过'&'在网址中
我正在尝试使用 urlencode 和以下代码在 python 中构建 url:
url = "https://api.geoapify.com/v1/geocode/search?"
search_params = {
'text': 'location',
'apiKey': 'XXX'
}
print(url + urlencode(search_params))
返回: https://api.geoapify.com/v1/geocode/search?text=location&apiKey=XXX
。它以某种方式取代了“&”通过 '& &'。
但是,我期望的是:https://api.geoapify.com/v1/geocode/search?text=location&apiKey=XXX
(这是可行的网址)。
奇怪的是,如果我删除 url 变量中的“http”: url = "api.geoapify.com/v1/geocode/search?"
并运行它返回的相同代码 api.geoapify.com/v1/geocode/search?text=location&apiKey =XXX
,并且不替换。
所以看起来 Jupyter (我在外面尝试过,它只是 Jupyter)识别出它是一个 url,并自动替换特殊字符。
有人知道如何避免 Jupyter 这样做吗?
谢谢!
I am trying to build url in python using urlencode with the following code:
url = "https://api.geoapify.com/v1/geocode/search?"
search_params = {
'text': 'location',
'apiKey': 'XXX'
}
print(url + urlencode(search_params))
Which returns: https://api.geoapify.com/v1/geocode/search?text=location&apiKey=XXX
. Somehow it replaces '&' by '& amp;'.
However, what I would expect is this: https://api.geoapify.com/v1/geocode/search?text=location&apiKey=XXX
(which is the url that would work).
Strangely if I remove the 'http' in the url variable:url = "api.geoapify.com/v1/geocode/search?"
and run the same code it returns api.geoapify.com/v1/geocode/search?text=location&apiKey=XXX
, and does not replace.
So it looks like Jupyter (I have tried outside and it is only Jupyter) recognizes that it is an url an automatically replaces special character.
Anybody have any idea how to avoid Jupyter to do that?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论