Programming considerations for python access to http applications

When Pyton requests Http, it must first establish a connection, and the address for establishing the connection must be the IP:PORT or domain name of the machine (the domain name resolution must also point to IP:PORT). This is different from programming in other languages ​​like Java.

If it is at the container application level, for example, you run an app application under Tomcat, if you go to xx.xx.xx.xx/app, it will not work, it must be xx.xx.xx.xx

So when you are programming, if someone else passes your address, you need to split("/")[0] when you use ip:PORT (or domain name), so be careful. The principle is to only take IP:PORT, remember.

Process as follows

def postMainHost(fileUrl, fileUUID):
    """
    Access the host, download the file content
    :param fileUrl::hostname orIP
    :param fileUUID: Unique ID of the downloaded file
    :return:
    """
    print "postMainHost"
    requrl = "http://{fileUrl}/commCallback/getFileContent".format(fileUrl=fileUrl)
    conn = httplib.HTTPConnection(fileUrl.split("/")[0])
    headers = {'content-type': 'application/json'}
    print requrl
    conn.request(method="POST", url=requrl, body=fileUUID, headers=headers)
    response = conn.getresponse()
    res = response.read()
    return res
 
 
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326865359&siteId=291194637