See above. Please move the not-None check to request(). Also note that if headers == [], it evaluates to False and a new empty list is always assigned. This is less efficient. Recommend to use the ternary expression here.