0
votes

where I want it to print out:

'HTTP ERROR

Successful Error

401: unauthorized'

so basically, I have created a function called def create_error_dictionary(error_codes,error_description), and what it does is that it would take the numbers of error_codes, and the string from error_descriptions and make the number the key of the dictionary, and the string the value of the dictionary. Then it returns the dictionary to the main, where it is used in def get_error_code_information (error,error_code_dictionary, error_category_dictionary). This function prints out the

HTTP ERROR

Successful Error

401: unauthorized

2 the .split() part, is to split 'status:HTTP/2.401', so that the list would look like this: [' 2 ', ' 401 '] after that, I made a for loop, to change the type from str to int, so that I can use it in my print statement, for indexing. But the problem is that when I run, there is a TypeError: 'int' object is not subscriptable. I'm stuck on how to print this information out, and also I would like to know if there is a way, that allows me to go from create_error_dictionary, to get_error_code_information without going to the main.

def create_error_dictionary(error_codes, error_descriptions):
    error_code_dict = {}
    v = 0
    for i in error_codes:
        error_code_dict[i] = error_descriptions[v]
        v += 1

    return error_code_dict
    


def get_error_code_information(error, error_code_dictionary, error_category_dictionary):

    split_num_HTTP_error = error.split('/')
    split_num_error = split_num_HTTP_error[1].split('.')
    for char in split_num_error:
        split_int_error = int(char)
    print(f'HTTP ERROR\n {error_category_dictionary[split_int_error[0]]} Error\n {split_int_error[1]}:{error_code_dictionary[split_int_error[1]]}')
          
          
          

          
error_codes = [400, 401, 402]

error_descriptions = ['Bad Request', 'Unauthorized', 'Payment Required']

error_category_dictionary={1:'Information', 2:'Successful', 3:'Redirection'}


a = create_error_dictionary(error_codes, error_descriptions)

print(get_error_code_information('status:HTTP/2.402',a, error_category_dictionary))

1

1 Answers

0
votes

You have a loop:

for char in split_num_error:
    split_int_error = int(char)

which is followed by code which does:

print(f'HTTP ERROR\n {error_category_dictionary[split_int_error[0]]} Error\n {split_int_error[1]}:{error_code_dictionary[split_int_error[1]]}')

Note how it indexes split_int_error at index 0 and 1, despite split_int_error being a single (not subscriptable) int.

Did you perhaps mean to do something like:

split_int_error = [int(char) for char in split_num_error]

so it was a list of all the integer converted components of split_num_error?