Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73409

Re: urllib/urllib2 support for specifying ip address

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!81.171.88.16.MISMATCH!hq-usenetpeers!hq-usenetpeers.eweka.nl!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'failing': 0.07; 'hosts': 0.07; 'subject:support': 0.07; '*args,': 0.09; 'assuming': 0.09; 'name?': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'apache': 0.15; '**kwargs)': 0.16; '**kwargs):': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hostname': 0.16; 'https': 0.16; 'normally,': 0.16; 'urllib2,': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'thu,': 0.19; 'solution.': 0.20; 'seems': 0.21; 'import': 0.22; 'accepted.': 0.22; 'tests': 0.22; 'cc:addr:python.org': 0.22; 'alternate': 0.24; 'cc:2**0': 0.24; 'mention': 0.26; 'query': 0.26; 'this:': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'host': 0.29; 'generally': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'run': 0.32; 'proceed': 0.33; "i'd": 0.34; 'could': 0.34; 'possible.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'should': 0.36; 'changing': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'server': 0.38; 'configured': 0.38; 'easiest': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'does': 0.39; 'though,': 0.39; 'address.': 0.39; 'according': 0.40; 'skip:u 10': 0.60; 'skip:o 30': 0.61; 'simply': 0.61; "you're": 0.61; 'address': 0.63; 'different': 0.65; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=/zFVwfUEg4ODdIQpfAm501pqzHaa2KCJFUdAZfGJGqA=; b=IfTZN/scTCH3QYxSXJMwvlnvcZ4HBGNvE6BdiX0r6Bi5Q55DBL97BxkEB7iIm9hdiJ qQcqdLH99BEsPSnH/+xZ9exUxzEEFphkTNslGc36UM7PthtefX4ofg95CxNt2tHu+K5s gZf+IGETzrMBdWQOs5f/f5zLpCT2+AuajAULj0PrFlmyQxAEYDexXfUB0rYS46wriann EgtrUkKIa8k+BiCEm5xPZenCc4tRNPjDEVErdxKPZtkpP64vlsWhGjhPGktGH1vx9YZd +cY9kySS2BrIWu2FZYlDApeYiJ9wmqcheCJle64y07W9XiPOPfBwCuz0TsjLXF6Ppm9O rzYA==
MIME-Version 1.0
X-Received by 10.58.160.164 with SMTP id xl4mr154487veb.38.1403171062138; Thu, 19 Jun 2014 02:44:22 -0700 (PDT)
In-Reply-To <53A2ABBB.3080907@chamonix.reportlab.co.uk>
References <53A2ABBB.3080907@chamonix.reportlab.co.uk>
Date Thu, 19 Jun 2014 19:44:22 +1000
Subject Re: urllib/urllib2 support for specifying ip address
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11138.1403171064.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1403171064 news.xs4all.nl 2849 [2001:888:2000:d::a6]:57814
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 4941
X-Received-Body-CRC 2183113418
Xref csiph.com comp.lang.python:73409

Show key headers only | View raw


On Thu, Jun 19, 2014 at 7:22 PM, Robin Becker <robin@reportlab.com> wrote:
> I want to run torture tests against an https server on domain A; I have
> configured apache on the server to respond to a specific hostname ipaddress.
>
> I don't want to torture the live server so I have set up an alternate
> instance on a different ip address.

Since you mention urllib2, I'm assuming this is Python 2.x, not 3.x.
The exact version may be significant.

Can you simply query the server by IP address rather than host name?
According to the docs, urllib2.urlopen() doesn't check the
certificate, so it should be accepted. Or does the server insist on
the hostname being correct?

Failing that, you could monkey-patch socket.create_connection, which
seems to be the thing that ultimately does the work. Something like
this:

import socket.
orig_create_connection = socket.create_connection
def create_connection(address, *args, **kwargs):
    if address == "domainA": address = "1.2.3.4"
    return orig_create_connection(address, *args, **kwargs)
socket.create_connection = create_connection
# Proceed to use urllib2.urlopen()

Untested, but may do what you want.

Normally, though, I'd look at just changing the hosts file, if at all
possible. You're right that it does change state for your whole
computer, but it's generally the easiest solution.

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: urllib/urllib2 support for specifying ip address Chris Angelico <rosuav@gmail.com> - 2014-06-19 19:44 +1000

csiph-web