Skip to content
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

D42 14600 - Lenovo Warranty Check Error #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions Files/warranty_ibm_lenovo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ def get_product_info(self, serials, retry=True):
timeout = 30

headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'ClientID': self.client_id
}

params = {
'Serial': serials
}

try:
resp = self.requests.get(self.url + '?Serial=' + serials, headers=headers, verify=True, timeout=timeout)
resp = self.requests.get(self.url, params=params, headers=headers, verify=True, timeout=timeout)
msg = 'Status code: %s' % str(resp.status_code)
if str(resp.status_code) == '401':
print '\t[!] HTTP error. Message was: %s' % msg
Expand All @@ -55,9 +60,10 @@ def get_product_info(self, serials, retry=True):
else:
return None
else:
# todo: used to get an example response for development
if self.debug:
print
print resp.json()
print
return resp.json()
except requests.RequestException as e:
self.error_msg(e)
Expand All @@ -84,7 +90,6 @@ def run_warranty_check(self, inline_serials, retry=True):
else:
full_serials.update({d42_serial: d42_serial})
inline_serials.append(d42_serial)
inline_serials = ','.join(inline_serials)

result = self.get_product_info(inline_serials, retry)
return result
Expand All @@ -93,16 +98,20 @@ def process_result(self, result, purchases):
global full_serials
data = {}

for item in result:
# The API returns results for single devices in a different format than multiple devices, this keeps everything
# returned from the API in the same list format
if 'Warranty' in result:
result = [result]

for item in result:
# Warranties
if 'Warranty' in item and len(item['Warranty']) > 0:
warranties = item['Warranty']
else:
continue

data.clear()
serial = item['ID']
serial = item['Serial']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like this was even being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, since we were waiting to get the script validated the changes to the script for the new API were based solely on the API docs. The docs stated that the following items would be returned. Serial number was not mentioned so I assumed serial number was listed as ID.

InWarranty - Whether this product is in warranty
Purchased - Date this product was purchased Will not be available if we do not have the purchase information (product was not registered)
Shipped - Date this product was shipped
Warranty - List of warranties
ID
Type
Name
Start
End
Contract - List of contract warranties. Available only if the product is part of a contract
Contract
Quantity
ItemNumber
ChargeCode
SLA
EntitlementCode
Status
Start
End


if self.order_no == 'common':
order_no = self.common
Expand All @@ -127,8 +136,8 @@ def process_result(self, result, purchases):
# process warranty line items for a device
for warranty in warranties:
try:
start_date = warranty['Start']['UTC'].split('T')[0]
end_date = warranty['End']['UTC'].split('T')[0]
start_date = warranty['Start'].split('T')[0]
end_date = warranty['End'].split('T')[0]
except (KeyError, AttributeError):
continue

Expand Down