-
Notifications
You must be signed in to change notification settings - Fork 62
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
API ERROR 403 #181
Comments
https://www.catb.org/~esr/faqs/smart-questions.html#intro Without seeing your Python script (or a minimal Python script which reproduces the error), or the exact content of the error body and server logs, there is no way we can know what's going on with your system. We don't even know if you're using a generic HTTP client like requests, or a Netdot-specific client library like netdot on pypi. |
I use the python requests library. As for my script, I can only give the anonymized version:
|
Try printing Try looking in your Apache logs (typically |
Here is the answer given by
For Apache logs, I'm waiting for my manager to give me access to the machine itself. |
OK, so it wants you to login via a form. It looks like it's not happy to accept HTTP Basic Auth. I don't have a running Netdot instance to test with, but I do note that the python 'netdot' library I referred you to before uses the login form to authenticate (in
If you want to login this way using the requests library, you'll want to use a Session so that the cookie is retained and passed to subsequent requests. The other thing I note from that code is that it sets an Accept header asking for XML:
(Yes, it does appear to send the literal string |
I've updated my code to look like this: import requests
import xmltodict
import json
class NetDotClient:
def __init__(self, base_url='https://netdotserver.com/netdot/rest/', timeout=5):
self.server = base_url
self.timeout = timeout
self.http = requests.Session() # creates a session
self.username = "username"
self.password = "password"
self.http.auth = (self.username, self.password) # sets HTTP Basic Auth for the session
self.http.headers.update(
{
'User_Agent': 'Netdot::Client::REST/1.0', # assuming that 1.0 is your version
'Accept': 'text/xml; version=1.0',
}
)
def get_ipblock(self):
url = self.server + 'ipblock'
try:
response = self.http.get(url, timeout=self.timeout)
response.raise_for_status()
except requests.RequestException as e:
print(f"An error occurred while trying to retrieve ipblock: {e}")
return None
data = xmltodict.parse(response.text) # Converts XML to Python dictionary
json_data = json.dumps(data, indent=4) # Converts Python dictionary to JSON
print(json_data)
if __name__ == "__main__":
client = NetDotClient()
client.get_ipblock() Despite this, it continues to give me a 403 error. |
You'll need to make a http.post with the login form details, like the code I showed you. |
Hello,
I'm trying to access the Netdot API to process data via a python script but I'm getting 403 errors. Even when I enter my credentials in the script.
Do you have a solution?
The text was updated successfully, but these errors were encountered: