OpenIxia / ixnetwork_restpy

The IxNetwork python client.
https://openixia.github.io/ixnetwork_restpy/#/
MIT License
30 stars 16 forks source link

requests.exceptions.InvalidURL: Failed to parse: https://[2600:111/api/v1/sessions #26

Closed maxdevyatov closed 4 years ago

maxdevyatov commented 4 years ago

IPv6 redirects are not handled properly. I've got below exception while. trying to connect to IPv6 API server.

requests.exceptions.InvalidURL: Failed to parse: https://[2600:111/api/v1/sessions

The issue is only seen with Windows based IxNetwork 9.05. IxNetwork started redirecting requests from HTTP to HTTPS protocol. When ixetwork-restpy receives HTTP redirect it executes this part of the code Link to the code

if str(response.status_code).startswith('3'):
    url = response.headers['location']
    if url.find('://') != -1:
        self._scheme = url[:url.find('://')]
        self._hostname = url[url.find('://')+3:url.find('/', url.find('://')+3)]
        if self._scheme == 'https':
            self._rest_port = 443
        host_pieces = self._hostname.split(':')  #IPv6 address/port wrongly split using colon
        if len(host_pieces) > 1:
            self._hostname = host_pieces[0]
            self._rest_port = host_pieces[1]
Request:
method:POST
url:http://[2600:111:111:111::c]:11009/api/v1/auth/session
data:{"username": "admin", "password": "admin"}
headers:{'X-Api-Key': None, 'User-Agent': 'ixnetwork-restpy', 'content-type': 'application/json', 'Content-Type': 'application/json'}

Response:
status:307
headers:{'Location': 'https://[2600:111:111:111::c]:11009/api/v1/auth/session',
    'Access-Control-Allow-Origin': '*',
    'Access-Control-Allow-Methods': '* ',
    'Connection': 'Close'}
ajbalogh commented 4 years ago

Hi Max, thanks for posting this issue, this will be addressed in the next version.

ajbalogh commented 4 years ago

fixed in build 1.0.0.59