获取错误“ValueError:int()的无效文字,基数为10:'3128;'在运行Tensorflow培训示例时

时间:2018-02-08 16:35:28

标签: python tensorflow urllib

所以我确实将错误一直追溯到原始文件“client.py”,错误显然是 host 变量上留下了一个分号。我实际上只是通过FROM tensorflow示例运行示例代码,我不希望我被要求更改任何这些文件。知道分号来自何处?我正在使用py = python3来执行,但我没有改变任何东西

在iris_data.py中传递的变量是

  

TRAIN_URL =“http://download.tensorflow.org/data/iris_training.csv

     

TEST_URL =“http://download.tensorflow.org/data/iris_test.csv

C:\Python3\Lib\site-packages\tensorflow\models\samples\core\get_started>py premade_estimator.py
Downloading data from http://download.tensorflow.org/data/iris_training.csv
Traceback (most recent call last):
  File "C:\Python3\lib\http\client.py", line 798, in _get_hostport
    port = int(host[i+1:])
ValueError: invalid literal for int() with base 10: '3128;'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "premade_estimator.py", line 88, in <module>
    tf.app.run(main)
  File "C:\Python3\lib\site-packages\tensorflow\python\platform\app.py", line 124, in run
    _sys.exit(main(argv))
  File "premade_estimator.py", line 34, in main
    (train_x, train_y), (test_x, test_y) = iris_data.load_data()
  File "C:\Python3\Lib\site-packages\tensorflow\models\samples\core\get_started\iris_data.py", line 19, in load_data
    train_path, test_path = maybe_download()
  File "C:\Python3\Lib\site-packages\tensorflow\models\samples\core\get_started\iris_data.py", line 12, in maybe_download
    train_path = tf.keras.utils.get_file(TRAIN_URL.split('/')[-1], TRAIN_URL)
  File "C:\Python3\lib\site-packages\tensorflow\python\keras\_impl\keras\utils\data_utils.py", line 238, in get_file
    urlretrieve(origin, fpath, dl_progress)
  File "C:\Python3\lib\urllib\request.py", line 188, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "C:\Python3\lib\urllib\request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python3\lib\urllib\request.py", line 466, in open
    response = self._open(req, data)
  File "C:\Python3\lib\urllib\request.py", line 484, in _open
    '_open', req)
  File "C:\Python3\lib\urllib\request.py", line 444, in _call_chain
    result = func(*args)
  File "C:\Python3\lib\urllib\request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "C:\Python3\lib\urllib\request.py", line 1223, in do_open
    h = http_class(host, timeout=req.timeout, **http_conn_args)
  File "C:\Python3\lib\http\client.py", line 762, in __init__
    (self.host, self.port) = self._get_hostport(host, port)
  File "C:\Python3\lib\http\client.py", line 803, in _get_hostport
    raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
http.client.InvalidURL: nonnumeric port: '3128;'

1 个答案:

答案 0 :(得分:0)

我设法运行了这个示例,但没有解决URLproblem

  1. 将csv文件下载到get_started目录
  2. 打开iris_data.py并将TRAIN_URL和TEST_URL的路径设置为csv文件

    TRAIN_URL = "iris_training.csv"
    TEST_URL = "iris_test.csv"
    
  3. 找到maybe_download函数(第11行),注释掉实现
  4. 转到函数load_data()并注释掉maybe_download()函数调用行
  5. 在其下方和pd.read_csv

    之前设置train_path = TRAIN_URL和test_path = TEST_URL
    train_path = TRAIN_URL 
    test_path = TEST_URL 
    train = pd.read_csv(train_path, names=CSV_COLUMN_NAMES, header=0)