Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I need a little help with python3 code. I wrote a code for python2, but after a little modifications in python3, I can't get this code working again.

Can you provide me any ideas, what and how can be done, to get this code working again?

#!/usr/bin/env python
# python3 version http client

import urllib.parse
import urllib.request
import time

param1 = 'value1'
param2 = 'value2'

tm = 60

while True:
    url = ""
    values = {'param1':value1, 'param2':value2}

    data = urllib.parse.urlencode(values)
    binary_data = data.encode('ascii')
    req = urllib.request.Request(url, binary_data)

    # find only cmd output:
    result ='Wireless(.*)</div>', data)
    print (

Code seems to be ok, but I need to add here basic auth login functionality. I know that in Python 3 auth was changed to oauth, but I don't know how should I prepare this code to working.

Any idea is welcome.

share|improve this question
This question somehow lacks a relation to Ubuntu. – Takkat May 24 '13 at 8:11
If the OP is using Ubuntu and chooses to post his question here it is totally on topic for the site. No further explanations needed. – Bruno Pereira May 24 '13 at 8:32
This isn't the code you are using, it contains multiple errors (just from sight alone). Provide a minimal working example and errormessages. – Timo May 24 '13 at 9:17

1 Answer 1

I'm not sure what you are trying to do but if any idea is welcome I'd suggest using requests instead of urllib.

If you need authentication ideas, they are here for you.

share|improve this answer
+1 for python-requests over urllib. Way more intuitive to accomplish this. – gertvdijk May 24 '13 at 9:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.