No offence, but this doesn't make any sense. P0171 means that the engine is either getting too much air or not enough fuel. A loose gas cap would throw an Evap code, not a Lean code. If you cleared the code then it might not necessarily come back right away. How long ago did this happen?
As far as the OP's question, P0171 in my experience is not usually a sensor issue but it's possible.
The most common issue is a cracked/broken intake or vacuum hose AFTER the MAF sensor - this sensor reads the incoming air and tells the ECM how much fuel to spray from the injectors, so if there is a leak after the MAF then there is unmetered air getting into the combustion chamber - too much air/not enough fuel.
Now, since there is only the single code for bank 1, there are a couple different things. Either both banks are lean, but the data list parameters haven't quite hit the limit to throw the code for bank 2 - OR the lean condition really is limited to bank 1 after which point I would check the intake manifold gasket for bank 1 to make sure it hasn't torn.
These aren't the only options but just food for thought, obviously check for any exhaust leaks close to the O2 sensors.
Good luck!