English 中文(简体)
PY4E:从进入的陶尔链路中检索档案
原标题:PY4E: Can t retrieve file from the url link entered
  • 时间:2023-12-27 19:35:49
  •  标签:
  • python
  • http

页: 1

我在为PY4E第12章做第1项工作,不能说明为什么该档案在终端站打印,我回答“HTTP/1.1 404sheng Not”

“error”/

问题:促使URL用户阅读任何网页。 您可使用分部分(/)将URL分解成其组成部分,以便你为接线电话提取主名。 在用户进入使用不当格式或不存在的URL的情况下,添加使用试验进行核对的错误,除非处理条件。

守则一写道:

import socket

try: 
    url = input( Enter URL here:  )
    new_url = url.split( / )
    host = new_url[2]
    path =  /  +  / .join(new_url[3:]) 
    #print(new_url)
    #print(host)
    #print(path)

    mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    mysock.connect((host, 80))
    cmd = f GET {path} HTTP/1.0

 .encode()
    mysock.send(cmd)

    while True:
            data = mysock.recv(512)
            if len(data) < 1:
                break
            print(data.decode(),end=  )

    mysock.close()
except:
    print( url not found or has issue )

http://data.pr4e.org/romeo.txt"rel=“nofollow noretinger” http://data.pr4e.org/romeo.txt。 - 在浏览器中可以打开连接线,这样一米我会非常混淆,把404个没有发现的连接点归还。

最佳回答
问题回答

对于像我这样遇到同样问题的人,法典的细微行应当是:

cmd = f GET {path} HTTP/1.0 Host: {host} .encode()

以下解释:

主机:是吉大港管理人的一个领域,具体规定了服务器(主机)的域名。 该机长须在HTTP/1.1申请中填写,因为它表明服务器上的哪位主应处理这一请求。 对于拥有多个领域(虚拟托管)的服务器来说,这一点很重要。

{host}是您重新连接的服务器实际托管人。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签