Python script - How to set the right serwer, when I perform request/open of applicati

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ravenchild
    New Member
    • May 2012
    • 2

    Python script - How to set the right serwer, when I perform request/open of applicati

    Python 3.2.2
    I want to check HTTP status code (eg. 200 or 404) on some www application.
    There are five server, and each server have a copy of this www application (The user is automatically redirected to the application on the server with low traffic/sometimes on random server).
    Suppose that the name of servers is: 0,1,2,3,4
    I want to check HTTP status code on page of www application on a particular server (which I choose).
    I tried various options, three of them I pasted below (they works -always return 200, but choose not this server what I want):
    ====1====
    Code:
    import urllib.request,urllib.parse, http.cookiejar
    values2= {"server":"2"}
    data2 = urllib.parse.urlencode(values2)
    data2 = data2.encode("utf-8")
    request2 = urllib.request.Request(url,data2)
    cj2 = http.cookiejar.CookieJar()
    cj2.add_cookie_header(request2)
    urlOpener2 = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj2))
    url2 = urlOpener2.open(request2)
    x2 = url2.getcode()
    =========
    ====2====
    Code:
    import urllib.request
    headers1 = {"Set-Cookie":"serwer=2"}
    req1 = urllib.request.Request(url, None, headers1)
    t1 = urllib.request.urlopen(req1)
    coderesp1 = t1.getcode()
    =========
    ====3====
    Code:
    import urllib.request
    urlOpener3 = urllib.request.build_opener()
    urlOpener3.addheaders.append(("Set-Cookie", "serwer=2"))
    url3 = urlOpener3.open(url)
    x3 = url3.getcode()
    =========
    If you will have some questions about my problem, please write, I will immediately reply what you want to know.
Working...