简体   繁体   English

如何防止来自百分比编码 URL 的 python 请求包含分号?

[英]How to prevent python requests from percent encoding URLs contain semicolon?

I want to post some data to a url like http://www.google.com/;id=aaa我想将一些数据发布到像http://www.google.com/;id=aaa这样的http://www.google.com/;id=aaa
I use follow codes:我使用以下代码:

url = 'http://www.google.com/;id=aaa'
r = requests.post(url, headers=my_headers, data=my_data, timeout=10)

Unfortunately, I find requests just cut my uri to http://www.google.com/ without any warning...不幸的是,我发现requests只是在没有任何警告的情况下将我的 uri 剪切到http://www.google.com/ ......

Is there some way to pass the the parameters in their original form - without percent encoding?有没有办法以原始形式传递参数 - 没有百分比编码?

I try config={'encode_uri': False} but it was abandoned, and urllib.unquote wasn't useful as well.我尝试config={'encode_uri': False}但它被放弃了,并且urllib.unquote也没有用。

Thanks!谢谢!

RFC 2616, section 3.2.2 specifies the syntax of an HTTP URL as: RFC 2616 第 3.2.2 节将 HTTP URL 的语法指定为:

http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]

It also says:它还说:

If the abs_path is not present in the URL, it MUST be given as "/" when used as a Request-URI for a resource如果 abs_path 不存在于 URL 中,则在用作资源的请求 URI 时必须将其指定为“/”

In this URL:在这个网址中:

http://www.google.com;id=aaa

there is no / , so there is no abs_path and there is no : , so there is no port .没有/ ,所以没有abs_path也没有: ,所以没有port It means that www.google.com;id=aaa is hostname.这意味着www.google.com;id=aaa是主机名。

Semicolons are not allowed in hostnames (see this answer for what is allowed in hostname), so this URL is invalid .主机名中不允许使用分号(有关主机名中允许的内容,请参阅此答案),因此此URL 无效

This would be a valid URL, if id=aaa should be part of the path:如果id=aaa应该是路径的一部分,这将是一个有效的 URL:

http://www.google.com/;id=aaa

This also, if id=aaa should be part of the query:这也是,如果id=aaa应该是查询的一部分:

http://www.google.com/?;id=aaa

EDIT编辑

The question has been modified to ask about http://www.google.com/;id=aaa instead.该问题已修改为询问http://www.google.com/;id=aaa

That URL is valid, and as far as I was able to test it, handles it without any problems.该 URL 是有效的,就我能够对其进行测试而言, 可以毫无问题地处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM