Unable to import Request Library in Robot Framework

Unable to import Requests Library in Robot Framework. Always getting error when trying to import the requests library. Can anyone please provide solution to import the library? Please find the software version details below.

Python=2.7.9
requests=2.24.0
robotframework=3.0
robotframework-requests=0.9.6
robotframework-ride=1.5.2.1

Hi Raagul,

All I’ve ever needed to do is put this in the beginning of my robot file:

*** Settings ***
Library 	RequestsLibrary

After that just use the Requests Library keywords in my test cases.

Is that what you’re doing? what errors are you getting?

Dave.

Hi Dave,

Yes, I am using as you mentioned. But the library is not getting imported. It is always displaying in Red color. Upon right clicking it is showing Edit, Move Up, Move Down, Delete and Import Library Spec XML options.

Raagul

Hi Raagul,

That sound like an issue with your editor’s syntax highlighting system not robot framework.

Mention which editor you’re using and what robot framework related plugin you have and hopefully someone who’s familiar with them can help you.

Dave.

Hi Dave,

I’m using RIDE. Able to use other libraries and keywords. Facing issue only with RequestsLibrary.

Thanks,
Raagul

It may take some time to get the keywords Documentation in RIDE.
If the library actually failed to import, you see errors logged in Tools->View RIDE Log.

Hi Helio Guiherme66,

Verified the logs from Tools → View Ride Log. Getting below error message. Could you please help?

Traceback (most recent call last):
Importing test library ‘RequestsLibrary’ failed: SyntaxError: invalid syntax (core.py, line 17)
Traceback (most recent call last):
File “C:\Python27\lib\site-packages\robotide\lib\robot\utils\importer.py”, line 143, in import
return__import
_ (name, fromlist= fromlist)
File “C:\Python27\lib\site-packages\RequestsLibrary_init_.py”, line 1, in
from .DeprecatedKeywords import DeprecatedKeywords
File “C:\Python27\lib\site-packages\RequestsLibrary\DeprecatedKeywords.py”, line 6, in
from RequestsLibrary import utils
File “C:\Python27\lib\site-packages\RequestsLibrary\utils.py”, line 5, in
from requests.status_codes import codes
File “C:\Python27\lib\site-packages\requests-2.24.0-py2.7.egg\requests\ __ init__.py”, line 120, in
from . import utils
File “C:\Python27\lib\site-packages\requests-2.24.0-py2.7.egg\requests\utils.py”, line 25, in
from . import certs
File “C:\Python27\lib\site-packages\requests-2.24.0-py2.7.egg\requests\certs.py”, line 15, in
from certifi import where
File “C:\Python27\lib\site-packages\certifi-2023.07.22-py2.7.egg\certifi__init__py”, line 1, in
from .core import contents, where

Thanks,
Raagul

Must you use Python 2.7?

You can try to re-install Requests.

pip install --force --upgrade requests

Yes, I must use Python 2.7.
Upgrade requests to latest version is not working.

Hi Raagul,

Just be aware that Python 2.x has been End of Life for 3 years now, so more and more libraries will not work with Python 2 as time progresses. As you are using a non supported version of Python it will be very difficult for anyone to help you.

Not sure what your organisations justification for staying on Python 2 is, but the sooner you move to a supported Python version the easier your life will be, at this point you’ve had 15 years (EOL was announced in 2008) to move to python 3.x.

Perhaps your best bet for now would be to find out what the last version of requests that was supported on Python 2 was and downgrade to that version of requests, not sure if that will fix your issue or not but worth a try.

I haven’t used Python 2 for about 4-5 years, sorry I can’t be more help than that.

Dave.