skip to Main Content

When I access

http://my_site.com/api/my_project/submitSearch.php?skills=C+OR+%28C%2B%2B+AND+UML%29

I get an HTTP response of 403.

The point being that I am encoding skill=C OR (C++ AND UML) in Python using urllib.parse.quote_plus().

If I use skill=(C++ AND UML), then there is no problem.

http://my_site.com/api/my_project/submitSearch.php?skills=%28C%2B%2B+AND+UML%29

I can only assume that the URL is triggering some Apache config rule. I asked my ISP and their solution was to allow all access from my current IP address. BUT, I want to allow everyone to access this URL, so how can I configure my Apache to allow this?

OR, am I wrongly encoding my URL in Python? Strangely, when I use encodeURIComponent() in JavaScript, the server does not reject the request.

So, the JS/Python encodings are

Python: http://localhost/api/enigma/submitSearch.php?skills=C+OR+%28C%2B%2B+AND+UML%29

JS:        http://localhost/api/enigma/submitSearch.php?skills=C%20OR%20(C%2B%2B%20AND%20UML)

Also, the problem is only at my ISP, not on localhost

2

Answers


  1. I’m not familiar with Apache, so I can’t help you there.

    To get the same output as JavaScript’s encodeURIComponent, try using urllib.parse.urlencode with urllib.parse.quote (instead of quote_plus).

    query = {"skills": "C OR (C++ AND UML)"}
    query_string = urllib.parse.urlencode(query, safe="-_.!~*'()", quote_via=urllib.parse.quote)
    print(query_string)
    

    skills=C%20OR%20(C%2B%2B%20AND%20UML)

    Login or Signup to reply.
  2. You could try adding an .htaccess file to the directory (or even root directory of your website) containing the content in your Apache server in the relevant directory. This should grant access to anyone that tries to access the dir.

     Allow From All
     Satisfy Any
     AllowOverride
    

    You can even wrap these directives like so:

    <Directory "/path/to/mysubdirectory">
     Allow from All
     Satisfy Any
     AllowOverride
    </Directory>
    

    to make it apply to a given dir.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search