我想更改给定网址中的端口.
OLD = http://test:7000/vcc3
NEW = http://test:7777/vcc3
我尝试下面的代码,我能够更改URL但无法更改端口.
>>> from urlparse import urlparse
>>> aaa = urlparse('http://test:7000/vcc3')
>>> aaa.hostname
test
>>> aaa.port
7000
>>>aaa._replace(netloc=aaa.netloc.replace(aaa.hostname,"newurl")).geturl()
'http://newurl:7000/vcc3'
>>>aaa._replace(netloc=aaa.netloc.replace(aaa.port,"7777")).geturl()
Traceback (most recent call last):
File "",line 1,in
TypeError: expected a character buffer object