pythonpython-3.xpylintpylintrc

C0209: Formatting a regular string which could be a f-string (consider-using-f-string)


For the below line, I am getting pylint issue: " C0209: Formatting a regular string which could be a f-string (consider-using-f-string)"

auth = str(base64.b64encode(bytes("%s:%s" % (self.user, self.password), "utf-8")), "ascii").strip()

I tried resolving it, but I am not sure if it is the right way to fix it. Can someone please advise?

auth = str(base64.b64encode(bytes(f'{self.user, self.password}', "utf-8")), "ascii").strip()

Solution

  • auth = str(base64.b64encode(bytes(f'{self.user}:{self.password}', "utf-8")), "ascii").strip()
    

    You may not be using the f-string correctly, change f'{self.user, self.password}' to f'{self.user}:{self.password}'

    More info