Python Forum
AttributeError: 'list' object has no attribute 'upper'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: 'list' object has no attribute 'upper'
#1
Get the AttributeError: 'list' object has no attribute 'upper'
Return this line the keywords 'upper'
def keygen(self, gp, sk, i, gid, pkey):
h = gp['H'](gid) 
K = (gp['g'] ** sk[i.upper()]['alpha_i']) * (h ** sk[i.upper()]['y_i'])
        
        pkey[i.upper()] = {'k': K}
        pkey['gid'] = gid
        if(debug):
            print("Key gen for %s on %s" % (gid, i))
            print("H(GID): '%s'" % h)
            print("K = g^alpha_i * H(GID) ^ y_i: %s" % K)
        return None
Error:
Traceback (most recent call last): File "/home/ali/Downloads/MedShare2021-main/test.py", line 9, in <module> class Dabe(ABEncMultiAuth): File "/home/ali/Downloads/MedShare2021-main/test.py", line 25, in Dabe for i in usr_attrs1,usr_attrs2: dabe.keygen(public_parameters, master_secret_key, i, ID, secret_keys) File "/usr/local/lib/python3.9/dist-packages/Charm_Crypto-0.50-py3.9-linux-x86_64.egg/charm/schemes/abenc/dabe_aw11.py", line 95, in keygen K = (gp['g'] ** sk[i.upper()]['alpha_i']) * (h ** sk[i.upper()]['y_i']) AttributeError: 'list' object has no attribute 'upper' Process finished with exit code 1
Reply
#2
Nobody can do anything with this snippet.
As the error message says, there is no 'upper' in a list, only in a string.
The indentation is wrong too.
Reply
#3
@ Axel_Erfurt before modifying the code running after I modify the code give an error but the keywords 'upper is already in the code.
Reply
#4
You only call "i.upper()", so "i" must be a list. You can ask if i is a list.
def keygen(self, gp, sk, i, gid, pkey):
    print(i, type(i))   # What is the type of i?
    h = gp['H'](gid) 
    K = (gp['g'] ** sk[i.upper()]['alpha_i']) * (h ** sk[i.upper()]['y_i'])

    pkey[i.upper()] = {'k': K}
    pkey['gid'] = gid
    if(debug):
            print("Key gen for %s on %s" % (gid, i))
            print("H(GID): '%s'" % h)
            print("K = g^alpha_i * H(GID) ^ y_i: %s" % K)
    return None
If "i" is a list your are also going to have a problem with sk[i]. You cannot use a list as a key for a dictionary (list is not a hashable type), so "i" is guaranteed to not match any of the keys in "sk".

After you change the calling code to pass a string instead of a list, I would also modify the function so you don't have to keep calling ".upper()"
[python]def keygen(self, gp, sk, i, gid, pkey):
    i = i.upper()
    h = gp['H'](gid) 
    K = (gp['g'] ** sk[i]['alpha_i']) * (h ** sk[i]['y_i'])

    pkey[i] = {'k': K}
    pkey['gid'] = gid
    if(debug):
            print("Key gen for %s on %s" % (gid, i))
            print("H(GID): '%s'" % h)
            print("K = g^alpha_i * H(GID) ^ y_i: %s" % K)
    return None
[/python]
Reply
#5
@deanhystad yes right I got your point
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 783 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 1,725 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Python: Regex is not good for re.search (AttributeError: 'NoneType' object has no att Melcu54 9 1,510 Jun-28-2023, 11:13 AM
Last Post: Melcu54
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 762 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 3,912 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  Object attribute behavior different in 2 scripts db042190 1 745 Jun-14-2023, 12:37 PM
Last Post: deanhystad
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,378 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,656 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  Replace with upper(string) WJSwan 7 1,587 Feb-10-2023, 10:28 AM
Last Post: WJSwan
  add object and name in list 3lnyn0 4 1,285 Nov-24-2022, 07:33 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020