robotframework-httplibrary icon indicating copy to clipboard operation
robotframework-httplibrary copied to clipboard

Import failing on Python 3.6

Open joaonc opened this issue 7 years ago • 17 comments

There's an unsupported syntax in HttpLibrary init.py

except ValueError, e:

is not supported in Python 3.6 (maybe other versions as well, not sure). Updating to

except ValueError as e:

works for Python 2.7 and above (maybe for lower versions of Python as well, not sure).

Also: from urllib import urlparse becomes from urllib.parse import urlparse

and it's failing on importing livetest. Tried from HttpLibrary import livetest but that's not working.

joaonc avatar Dec 05 '17 22:12 joaonc

Ok, got the imports for Python 3.6:

  • __init__.py
from robot.api import logger

from base64 import b64encode
from functools import wraps
from urllib.parse import urlparse

from HttpLibrary import livetest
import json
import jsonpointer
import jsonpatch
  • livetest.py
import sys
import webtest
import http.client
from urllib.parse import urlparse
from http.cookies import BaseCookie, CookieError
from six.moves import http_cookiejar

conn_classes = {'http': http.client.HTTPConnection,
                'https': http.client.HTTPSConnection}

joaonc avatar Dec 05 '17 23:12 joaonc

Also in livetest.py, line 121: iteritems() should be updated to items()

headers = dict((name, val) for name, val in req.headers.items())

joaonc avatar Dec 05 '17 23:12 joaonc

hey @joaonc I am having the same issues. Do we need to make all changes for the library to work ?

aks1589 avatar Jan 22 '18 03:01 aks1589

@aks1589 I'm pretty sure this is a defunct project and will never work in Python 3.x unless someone picks it up. What we're doing is we're moving away from using this library altogether and have our own layer in Python (and imported as a library) that does the REST calls, using Python's requests library.

joaonc avatar Jan 24 '18 21:01 joaonc

thanks for the reply @joaonc ! Thats disappointing considering the functions this library had to offer. I am now using the requests library for my test cases.

aks1589 avatar Jan 25 '18 00:01 aks1589

Any updates on this? Im using now Python 3.7 and the issue is still on it

jmagaru avatar Oct 09 '18 06:10 jmagaru

@jmagaru I don't think there will be any updates on this as this seems to be a defunct project. My recommendation is that you don't use this library.

joaonc avatar Oct 14 '18 20:10 joaonc

@joaonc Have you any recommendations instead this library?

pablogiroud avatar Jan 24 '19 19:01 pablogiroud

@pablogiroud I don't know. Maybe Robot Framework already provides some functionality in its libraries.

What I did was created a Python module using the requests package, which makes doing REST calls super easy, and imported it into Robot as a library.

joaonc avatar Jan 24 '19 20:01 joaonc

Yes request library looks easy to use. https://github.com/bulkan/robotframework-requests

jmagaru avatar Jan 25 '19 00:01 jmagaru

thanks @joaonc and @jmagaru !!!

pablogiroud avatar Jan 25 '19 14:01 pablogiroud

@peritus , Is there a plan to support this library for Python 3.x?

vinaybond avatar Feb 06 '19 06:02 vinaybond

Can someone help me also i am getting this error Importing test library 'HttpLibrary.HTTP' failed: SyntaxError: invalid syntax (__init__.py, line 16) Traceback (most recent call last) pip list installed

Package Version asn1crypto 0.24.0
beautifulsoup4 4.7.1
certifi 2019.3.9 cffi 1.12.2
chardet 3.0.4
cryptography 2.6.1
idna 2.8
ipaddress 1.0.22
jsonpatch 1.23
jsonpointer 2.0
pip 19.0.3
pycparser 2.19
pyOpenSSL 19.0.0
robotframework 3.1.1
robotframework-httplibrary 0.4.2
robotframework-seleniumlibrary 3.3.1
selenium 3.141.0 setuptools 39.1.0
six 1.12.0
soupsieve 1.9
urllib3 1.24.1
waitress 1.2.1
WebOb 1.8.5
WebTest 2.0.33 `

Gurinder-Bhachu avatar Mar 28 '19 20:03 Gurinder-Bhachu

i am getting the same error,please to help me

20191114 09:22:58.857 [WARN]: Importing test library "HttpLibrary" failed

Traceback (most recent call last):
Importing test library 'HttpLibrary' failed: SyntaxError: invalid syntax (__init__.py, line 16)
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/lib/robot/utils/importer.py", line 153, in _import
    return __import__(name, fromlist=fromlist)
PYTHONPATH:
  /usr/local/bin
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/spec
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/lib
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/contrib/testrunner/../../lib
  /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/contrib/testrunner/../../lib
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/spec/librarymanager.py", line 87, in _fetch_keywords
    return get_import_result(path, library_args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/spec/libraryfetcher.py", line 24, in get_import_result
    lib = robotapi.TestLibrary(path, args)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/lib/robot/running/testlibraries.py", line 50, in TestLibrary
    return_source=True)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/lib/robot/utils/importer.py", line 72, in import_class_or_module
    self._raise_import_failed(name, err)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/robotide/lib/robot/utils/importer.py", line 109, in _raise_import_failed
    raise DataError('\n'.join(msg))

herry-ff avatar Nov 14 '19 01:11 herry-ff

I have the same issue.

but i have install HttpLibrary.HTTP.

robotframework (3.1.2) robotframework-httplibrary (0.4.2) robotframework-requests (0.6.2) robotframework-ride (1.7.4a1) robotframework-selenium2library (3.0.0) robotframework-seleniumlibrary (4.1.0) robotframework-seriallibrary (0.3.1) robotframework-sshlibrary (3.4.0)

`20191217 16:04:52.554 [WARN]: Importing test library "HttpLibrary.HTTP" failed

Traceback (most recent call last): Importing test library 'HttpLibrary.HTTP' failed: SyntaxError: invalid syntax (init.py, line 16) Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/robotide/lib/robot/utils/importer.py", line 153, in _import return import(name, fromlist=fromlist) PYTHONPATH: /usr/lib/python36.zip /usr/lib/python3.6 /usr/lib/python3.6/lib-dynload /home/zhaobin/.local/lib/python3.6/site-packages /usr/local/lib/python3.6/dist-packages /usr/lib/python3/dist-packages /usr/local/lib/python3.6/dist-packages/robotide/spec /usr/local/lib/python3.6/dist-packages/robotide/lib /usr/local/lib/python3.6/dist-packages/robotide/spec /usr/local/lib/python3.6/dist-packages/robotide/lib /usr/local/lib/python3.6/dist-packages/robotide/contrib/testrunner/../../lib /usr/local/lib/python3.6/dist-packages/robotide/contrib/testrunner/../../lib File "/usr/local/lib/python3.6/dist-packages/robotide/spec/librarymanager.py", line 87, in _fetch_keywords return get_import_result(path, library_args) File "/usr/local/lib/python3.6/dist-packages/robotide/spec/libraryfetcher.py", line 24, in get_import_result lib = robotapi.TestLibrary(path, args) File "/usr/local/lib/python3.6/dist-packages/robotide/lib/robot/running/testlibraries.py", line 50, in TestLibrary return_source=True) File "/usr/local/lib/python3.6/dist-packages/robotide/lib/robot/utils/importer.py", line 72, in import_class_or_module self._raise_import_failed(name, err) File "/usr/local/lib/python3.6/dist-packages/robotide/lib/robot/utils/importer.py", line 109, in _raise_import_failed raise DataError('\n'.join(msg)) `

zhaobin200306 avatar Dec 17 '19 08:12 zhaobin200306

Thanks to Author of this library. One of the best API library to use in Robot framework especially with session retained for subsequent requests in page object test automation model. This is not achievable using other libraries. So thought of fixing issues with this library for Python 3 and I was successful and it is working.

Python version I tried is python 3.8.1. As I do not know how to build test library for robot framework, someone here especially author could publish HTTPLIBRARY with latest attached files to support Python 3.

Note: install relevant libraries (pyparsing, urllib3, webtest) needed for this files.

Inside Zip files, there are 3 files, httplibs (previously init.py file in library), livetest and httprequest. Use only httplibs and livetest to build library.

Whereas, httprequest python file can be imported to robotframework and could use keywords as temporary solution until library available.

http.zip

Sathish787 avatar Jan 02 '20 18:01 Sathish787

is this library not to be used? I am also getting same error Importing test library 'HttpLibrary.HTTP' failed: SyntaxError: invalid syntax (init.py, line 16)

syed-wasim avatar Sep 12 '20 07:09 syed-wasim