Coder Social home page Coder Social logo

Comments (3)

dysbulic avatar dysbulic commented on June 22, 2024

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

from multipartposthandler.

dysbulic avatar dysbulic commented on June 22, 2024

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?

from multipartposthandler.

avikaps avatar avikaps commented on June 22, 2024

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)

from multipartposthandler.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.