microsoft/IoT-For-Beginners

RequestsDependencyWarning when attempting to connect Pi device to IoT Hub

marty-optum opened this issue · 3 comments

I am going through the Connect your IoT device to the cloud - Virtual IoT Hardware and Raspberry Pi lesson. I am using VS Code on a Mac as my IDE, and connecting to the Pi remotely using the Remote SSH extension.

I followed the instructions to install the azure-iot-device libraries by typing pip3 install azure-iot-device.

I then followed instructions in step 3 to "Add the following imports to the top of the app.py file, below the existing imports:" from azure.iot.device import IoTHubDeviceClient, Message, MethodResponse

When I do this however, it seems that VS code is not able to resolve the azure.iot.device library. In fact, the azure.iot.device string has an orange squiggly line under it. When I hover over this line, the following message is displayed: "Import "azure.iot.device" could not be resolvedPylancereportMissingImports". In addition, subsequent attempts to leverage IoTHubDeviceClient, Message, or MethodResponse objects do not trigger any Intellisense auto-suggestions.

Finally, I try running the code anyway as is suggested in Step 7. When I do this, I get the following output:

image

Can anyone else replicate this error? Any ideas what is wrong and how to fix? My guess is that there is a version issue in one of the dependencies. I tried updating Python3 and verified I am running the latest extensions in VS Code, but no luck.

Thanks for your ideas!

For the first issue, I've seen sometimes PyLance (the language server) doesn't pick up any newly installed packages that are installed after the file is opened via the terminal. You can force it to re-parse the file by closing it and re-opening it again.

For the second issue - I've seen that before and it's something gone awry in the versions needed of different libraries for different packages. If I try on a new install using the latest Bullseye I don't see it, so something I installed along the way upgraded a package. Try upgrading requests:

pip3 install --upgrade requests

and see if that fixes it.

@jimbobbennett , Thank you! That did the trick! Have a nice Thanksgiving holiday!

Hopefully, this will help out other students who come across the same problem. You may close this issue.