We had a similar issue before and one of our forum users found a round about to have it working. So they found that with time, values start appearing on the right port and they become consistent, so to avoid this problem, they ignored the values which were “Nan”. You can refer to the discussion here also you can use a code like the one below and let us know if that helps.
#!/usr/bin/env python
#
import grovepi
import math
import time
white = 1 # The White colored sensor.
while True:
for i in range(7,9):
[temp,humidity] = grovepi.dht(i,white)
time.sleep(1)
[temp,humidity] = grovepi.dht(i,white)
if math.isnan(temp) == False and math.isnan(humidity) == False:
print("Port#%d : temp = %.02f C humidity =%.02f%%"%(i, temp, humidity))
else:
print("Port#%d - Fail"%(i))
time.sleep(2)
print("---")