Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication failed while sending a request #1

Closed
avikaps opened this issue Sep 24, 2014 · 3 comments
Closed

Authentication failed while sending a request #1

avikaps opened this issue Sep 24, 2014 · 3 comments

Comments

@avikaps
Copy link
Owner

avikaps commented Sep 24, 2014

I have face an issue and could be it requires an update in the library. We are using lighttpd web server and our cgi-bin folder is protected with username and password.

Whenever we need to use the cgi files from that folder we need to authenticate it with the username and password.

This works fine when there are NO parameters attached in the request but fails when there are any parameters associated in the request.

Could you please help me how shall i authenticate the url when using the parameters in the request ?

@dysbulic
Copy link

I am really swamped atm. I don't know how soon I can get to it. I created a bounty to incentivize others.

@dysbulic
Copy link

From Stack Ovewrflow:


I'm using MultipartPostHandler to create multi part-form data requests.

We are using lighttpd web server and our cgi-bin folder is protected with username and password.

Whenever we access the cgi files, we need to authenticate.

This works fine when there are no parameters attached to the request, but fails with any parameters.

Could you please help me how I can authenticate when using parameters in the request ?

import MultipartPostHandler
import urllib2

def handle_authentication(url):
    """handle_authentication description"""
    try:
        passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
        passman.add_password(None, url, USERNAME, PASSWORD)
        authhandler = urllib2.HTTPBasicAuthHandler(passman)
        opener = urllib2.build_opener(authhandler)
        urllib2.install_opener(opener)
    except urllib2.HTTPError:
        print ERROR_300
        sys.exit(1)

Also:

params = {'BoardType': board_type, 'SataConfigFile': open(input_path, 'rb')}
opener = urllib2.build_opener(MultipartPostHandler.MultipartPostHandler)
print opener
try:
    handle_authentication(url)
    response = opener.open(url, params)

Do you have a solution?

@avikaps
Copy link
Owner Author

avikaps commented Oct 6, 2014

The solution is as follows - clubbing both (authentication and the Multi part request) request will solve the purpose for now. Is there any better solution available ??


import MultipartPostHandler
import urllib2
def handle_authentication(url):
"""handle_authentication description"""
try:
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, USERNAME, PASSWORD)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
return authhandler
except urllib2.HTTPError:
print ERROR_300
sys.exit(1)

Then in the main code . . .

 
params = {'BoardType': board_type, 'SataConfigFile': open(input_path, 'rb')}
authhandler = handle_authentication(url)
opener = urllib2.build_opener(authhandler, MultipartPostHandler.MultipartPostHandler)
print opener
try:
handle_authentication(url)
response = opener.open(url, params)

@avikaps avikaps closed this as completed Oct 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants