RESTful knowledge exchange
Post Reply
afang
Novice
Posts: 7
Liked: never
Joined: Jan 20, 2022 10:38 pm
Full Name: Allen Fann
Contact:

Unable to make any api call

Post by afang »

Hi all,

I'm trying to use the RESTful API in python, but I keep on getting this error: requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')).
I've done the following

Code: Select all

import requests

uri = "https://server-domain:9398/api/sessionMngr/?v=latest"
username = "..."
password = "..."
b64 = "..."
r = requests.get(uri, auth=(username, password), verify=False)
r = requests.get(uri, headers={'Authorization': f"Basic {b64}"}, verify=False)
When I try to go to the :9398/web page in Internet Explorer, I get an error: This page can't be displayed. Turn on TLS 1.0, TLS 1.1, and TLS 1.2 in Advanced settings and try connecting again.
Which I confirmed is already on.

Any leads would be helpful.
Thanks,
Allen
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Unable to make any api call

Post by ronnmartin61 »

I believe the issue is that you're trying "get" when you need to be using "post"

Code: Select all

veeam_url = 'https://vbackup.lab.com:9398/api/'
user = "LAB\Administrator"
password = 'mysecretpassword'

veeam_session = requests.session()
rval = veeam_session.post(veeam_url+'/sessionMngr/?v=latest', auth=(user, password), verify=False)
afang
Novice
Posts: 7
Liked: never
Joined: Jan 20, 2022 10:38 pm
Full Name: Allen Fann
Contact:

Re: Unable to make any api call

Post by afang »

Thanks for the reply, but I've modified my code but the error still persists. I've also tried

Code: Select all

r = requests.request("POST", ...)
and also tried a curl call

Code: Select all

curl -X POST -k -v -u username:password https://server-domain:9398/api/sessionMngr/?v=latest -H "Content-Length: 0"
which resulted in
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to server-domain:9398
* stopped the pause stream!
* Closing connection 0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to server-domain:9398
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Unable to make any api call

Post by ronnmartin61 »

Yep looks like it's changed since the old days when I wrote the script I pulled that code out of. Give something like this a go -

Code: Select all

import requests
import base64

user = 'VBR2019\Administrator'
password = '***'

eCreds = base64.b64encode(user+':'+password)
authHeader = {'Authorization': 'Basic ' + eCreds}

rval = requests.post('https://192.168.15.30:9398/api/sessionMngr/?v=latest', headers=authHeader, verify=False)
if (rval.status_code == 201):
    print('Session ID - ' + rval.headers['X-RestSvcSessionId'])
else:
    print('Error - ' + str(rval.status_code))
afang
Novice
Posts: 7
Liked: never
Joined: Jan 20, 2022 10:38 pm
Full Name: Allen Fann
Contact:

Re: Unable to make any api call

Post by afang »

Took a few changes because b64encode() takes and spits out a bytes-like objects, but here it is and the 104 error is still here.

Code: Select all

uri = 'https://server-domain:9398/api/sessionMngr/?v=latest'
username = '...'
password = '...'
userpass = username + ':' + password
b64 = base64.b64encode(userpass.encode()).decode()
headers={'Authorization': 'Basic ' + b64}
r = requests.get(uri, headers=headers, verify=False)
Some research leads me to believe it could be an ssl issue on the server side(?) or something else, but I'm not too sure what specifically I could look around in the backup enterprise manager or the windows server it's on to help locate why exactly these api calls aren't being responded to.
ronnmartin61
Veeam Software
Posts: 441
Liked: 131 times
Joined: Mar 07, 2016 3:55 pm
Full Name: Ronn Martin
Contact:

Re: Unable to make any api call

Post by ronnmartin61 »

Not sure however I'd suggest you try it with the single b64encode on your credentials as the second code snippet definitely works in my environment. Also (again) you need to post not "get" on the call...
chris.arceneaux
VeeaMVP
Posts: 668
Liked: 359 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Unable to make any api call

Post by chris.arceneaux »

Hi Allen,

Can you please confirm that server-domain in your URL is an Enterprise Manager server?

Code: Select all

uri = 'https://server-domain:9398/api/sessionMngr/?v=latest'
If you're trying to authenticate to the Veeam Backup & Replication RESTful API, a different port (9419) and corresponding API call should be used.

One method to validate the API is working correctly would be to test using their respective built-in web clients:
afang
Novice
Posts: 7
Liked: never
Joined: Jan 20, 2022 10:38 pm
Full Name: Allen Fann
Contact:

Re: Unable to make any api call

Post by afang »

Ah my mistake, I used the correct post call, but the error is still there.
The b64encode without encoding/decoding strings gives a TypeError: a bytes-like object is required, not 'str', and I have even tried placing a manually encoded string using base64encode.org in lieu of the function's output too.

I can confirm the server domain is correct, as I just used it to log onto the backup enterprise manager (the 9443 port), and checked the correct url in Configurations > About > Veeam RESTful API Service.
What I'm trying to get out of the api are the Reports (https://<Enterprise-Manager>:9398/api/reports/summary).

However one thing that is boggling is that the web client for the 9398 port can't be reached.
chris.arceneaux
VeeaMVP
Posts: 668
Liked: 359 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Unable to make any api call

Post by chris.arceneaux » 1 person likes this post

Given that the web client is not functioning, I recommend you open a Veeam support case to further troubleshoot. Either there exists an issue with the RESTful API service or a firewall could be blocking access to the port.

Once you are able to successfully test the web client, here's working Python 3 sample code I just tested in my lab:

Code: Select all

import requests
import base64

username = '...'
password = '...'
userpass = username + ':' + password
b64 = base64.b64encode(userpass.encode()).decode()

url = "https://<enterpise-manager>:9398/api/sessionMngr/?v=latest"

headers = {'Authorization': 'Basic ' + b64}
response = requests.post(url, headers=headers, verify=False)

print(response.headers)
afang
Novice
Posts: 7
Liked: never
Joined: Jan 20, 2022 10:38 pm
Full Name: Allen Fann
Contact:

Re: Unable to make any api call

Post by afang »

Thanks, I opened a support case. It's number is 05252939.
I also looked into firewall rules for inbound/outbound connections. The predefined rules, Veeam RESTful API Service (HTTP-Out, HTTP-In, HTTPS-Out, HTTPS-In), are enabled and allowed for all connections on ports 9399 and 9398.
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Unable to make any api call

Post by oleg.feoktistov »

Thanks for sharing your case number Allen, I'll monitor it closely. Let's see what our engineers discover. Cheers!
edxh
Veeam Software
Posts: 90
Liked: 32 times
Joined: Oct 04, 2019 6:39 pm
Full Name: Edward Howard
Contact:

Re: Unable to make any api call

Post by edxh » 2 people like this post

Hi there,

Minor point but you can make your life a little easier by doiung the following:

from requests.auth import HTTPBasicAuth

auth = HTTPBasicAuth(username, password)

res = requests.post(self.login_url, auth=auth, verify=False)

ref: https://docs.python-requests.org/en/mas ... ntication/

Ed
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest