Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I pulled this code from here: Dell API: Warranty Information · GitHub[^]

I made some changes:
Comment on Dell API: Warranty Information · GitHub

So the changed code:

Python
  1  #!/usr/bin/env python
  2  
  3  # Quick script to check your Dell asset's warranty status
  4  # Just drop your service tag as parameters for the script and go.
  5  
  6  import sys
  7  import requests
  8  
  9  APIKEY = 'd676cf6e1e0ceb8fd14e8cb69acd812d'
 10  URL = 'https://api.dell.com/support/v2/assetinfo/warranty/tags.json?svctags={0}&apikey=' + APIKEY
 11  
 12  def get_warr_from_dell(svctag):
 13      res = requests.get(URL.format(svctag))
 14  
 15      if res.status_code != 200:
 16          sys.stderr.write('[%s] Caught %i as the response code.\n' % (svctag, res.status_code))
 17          sys.stderr.write('[%s] Unable to get details for given service tag.\n'
 18                  % svctag)
 19          return False
 20  
 21      fault = res.json['GetAssetWarrantyResponse']['GetAssetWarrantyResult']['Faults']
 22      if fault is not None:
 23          sys.stderr.write("[%s] Failed to find details. Sure it's a valid TAG?\n" % svctag )
 24          return False
 25  
 26      asset = res.json['GetAssetWarrantyResponse']['GetAssetWarrantyResult']['Response']['DellAsset']
 27      model = asset['MachineDescription']
 28      ent = asset['Warranties']['Warranty']
 29      shipped = asset['ShipDate']
 30  
 31  print ('Service Tag:        ', svctag)
 32      print (' Model:             ', model)
 33      print (' Shipped:           ', shipped, '\n')
 34      print ('{0:<20} {1:>15}'.format(*('Warranty Ends','ServiceLevelDescription')))
 35      for warr in [(d['EndDate'],d['ServiceLevelDescription']) for d in ent]:
 36          print ('{0:<20} {1:>15}'.format(*warr))
 37  
 38  
 39  if __name__ == '__main__':
 40   get_warr_from_dell(sys.argv[0])
 41      sys.exit()


The errors and updates that come after running the above:

Terminal
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/usr/lib/python3.8/site-packages/urllib3/util/connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn
    conn.connect()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 308, in connect
    conn = self._new_conn()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7fa83d980850>: Failed to establish a new connection: [Errno -3] Try again
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 724, in urlopen
    retries = retries.increment(
  File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.dell.com', port=443): Max retries exceeded with url: /support/v2/assetinfo/detail/tags.json?svctags=main.py&apikey=d676cf6e1e0ceb8fd14e8cb69acd812d (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa83d980850>: Failed to establish a new connection: [Errno -3] Try again'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "main.py", line 36, in <module>
    get_parts(sys.argv[0])
  File "main.py", line 13, in get_parts
    res = requests.get(URL.format(svctag))
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.dell.com', port=443): Max retries exceeded with url: /support/v2/assetinfo/detail/tags.json?svctags=main.py&apikey=d676cf6e1e0ceb8fd14e8cb69acd812d (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa83d980850>: Failed to establish a new connection: [Errno -3] Try again'))


** Process exited - Return Code: 1 **
Press Enter to exit terminal 


What I have tried:

I have tried searching parts of errors but landed on nothing. Help is highly appreciated.
Also I tried making myself an API link(dunno if I made it correctly) by putting the api key and a working service tag to the URL and got something - and I can't find the browser history for it. But it looked exacltly like this, which is what you get on the api.dell.com:
Quote:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:body>
<soapenv:fault>
<faultcode>soapenv:Server
<faultstring>Policy Falsified
<faultactor>https://api.dell.com/
<detail>
<l7:policyresult xmlns:l7="http://www.layer7tech.com/ws/policy/fault" status="Service Not Found. The request may have been sent to an invalid URL, or intended for an unsupported operation.">



Posted
Updated 1-Oct-21 4:39am
v4
Comments
Richard MacCutchan 30-Sep-21 4:17am    
The message suggests that the Dell website did not accept your request. you should talk to the person who wrote the original code.
Gomesz785 30-Sep-21 4:27am    
What message? like which part?
Richard MacCutchan 30-Sep-21 4:34am    
HTTPSConnectionPool(host='api.dell.com', port=443): Max retries exceeded with url: /support/v2/assetinfo/detail/tags.json?svctags=main.py&apikey=d676cf6e1e0ceb8fd14e8cb69acd812d (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fa83d980850>: Failed to establish a new connection: [Errno -3] Try again'))

I do not think that svctags=main.py is correct.
Gomesz785 30-Sep-21 5:09am    
OK, I understood which part says they unaccepted the request. But why is the svctag thing/error important in this context? (sorry bad English)

I think the case is my code did not put a number to the svctags field on the URL and instead put the file name? strange.

Please advise me.
Richard MacCutchan 30-Sep-21 5:29am    
if __name__ == '__main__':
 get_warr_from_dell(sys.argv[0])
    sys.exit()

The value of sys.argv[0] will be the name of your main orogram. You should use sys.argv[1] and pass the required value when you run the program.

1 solution

You are still passing 'main.py' as the svctags parameter. Your code should be using sys.argv[1] like this:
Python
if __name__ == '__main__':
 get_warr_from_dell(sys.argv[1])
    sys.exit()

And your invocation of the program should be
python main.py XXX

where XXX is the service tag of your Dell device.
 
Share this answer
 
Comments
Gomesz785 1-Oct-21 0:53am    
Am I correct? : Please tell "Where" to put the invocation, I am not running this in my command line :-)
#!/usr/bin/env python

# Quick script to check your Dell asset's warranty status
# Just drop your service tag as parameters for the script and go.

import sys
import requests

python main.py XXX

APIKEY = 'd676cf6e1e0ceb8fd14e8cb69acd812d'
URL = 'https://api.dell.com/support/v2/assetinfo/warranty/tags.json?svctags={0}&apikey=' + APIKEY

def get_warr_from_dell(svctag):
res = requests.get(URL.format(svctag))

if res.status_code != 200:
sys.stderr.write('[%s] Caught %i as the response code.\n' % (svctag, res.status_code))
sys.stderr.write('[%s] Unable to get details for given service tag.\n'
% svctag)
return False

fault = res.json['GetAssetWarrantyResponse']['GetAssetWarrantyResult']['Faults']
if fault is not None:
sys.stderr.write("[%s] Failed to find details. Sure it's a valid TAG?\n" % svctag )
return False

asset = res.json['GetAssetWarrantyResponse']['GetAssetWarrantyResult']['Response']['DellAsset']
model = asset['MachineDescription']
ent = asset['Warranties']['Warranty']
shipped = asset['ShipDate']

print ('Service Tag: ', svctag)
print (' Model: ', model)
print (' Shipped: ', shipped, '\n')
print ('{0:<20} {1:>15}'.format(*('Warranty Ends','ServiceLevelDescription')))
for warr in [(d['EndDate'],d['ServiceLevelDescription']) for d in ent]:
print ('{0:<20} {1:>15}'.format(*warr))


if __name__ == '__main__':
get_warr_from_dell(sys.argv[0])
sys.exit()
Richard MacCutchan 1-Oct-21 3:30am    
Read my previous comment again. If you are not running this from the command line then how are you running it?

And what do you think that adding the following line at the top of your code will do?
python main.py XXX
Gomesz785 1-Oct-21 4:04am    
Your first question: online python editor
Your second question: No idea, how t add the invoke? mix it to the motherboard?
Richard MacCutchan 1-Oct-21 4:20am    
Well I have no idea which online editor you are referring to so I cannot make any suggestions.
Gomesz785 1-Oct-21 10:16am    
https://www.online-python.com/ also look this image, I was able to put the XXX into an virtual cmd line and then it started throwing intend errors(

File "main.py", line 32
print (' Model: ', model)
^
IndentationError: unexpected indent


** Process exited - Return Code: 1 **
Press Enter to exit terminal

), did you got them as well?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900