2

I'm working on Python3 with testing page load times so I created a local apache server for compare but the problem is I use urllib.request.urlopen(url) function which doesn't allow me to use my own ip address. Is there anything that helps me to get page with only ip address. Here's the code I working on;

start_loadf = time.time()
nf = urllib.request.urlopen(url) ##// I want here to be something like 192.168.1.2 
page = nf.read()
end_loadf = time.time()
nf.close()
reading_time = format(end_loadf-start_loadf,'.3f')
print("Kaynaktan alinan ilk okuma suresi : ", reading_time , "sn.")
Turquase
  • 83
  • 1
  • 12
  • Can you put in 'localhost' as your url? – Xenotoad May 11 '15 at 07:05
  • Working on 2 seperate virtual machine one of them tester other one is server. If I write there localhost then I only test my tester machine response. Edit: Also it requires a proper url address doesn't accepts that one too. – Turquase May 11 '15 at 07:38

1 Answers1

3

Solved the problem when I look in to urllib literally. Actually what I need is urllib2 but because of I'm using python3.4 I souldn't import urllib it causes python use urllib part not urllib2. After importing urlib.request only and writing the url part as http://192.168.1.2 instead of 192.168.1.2 it works fine.

import urllib.request
import time
import socket

nf = urllib.request.urlopen("http://192.168.1.2")
start_loadf = time.time()
page = nf.read()
end_loadf = time.time()
nf.close()
reading_time = format(end_loadf-start_loadf,'.3f')
print("Kaynaktan alinan ilk okuma suresi : ", reading_time , "sn.")
Turquase
  • 83
  • 1
  • 12