Fail importing REQUESTS python module

Hi all,

I am trying to import requests module into my gateway.
I have tried two different versions: requests-0.2.4 and requests-2.27.1

after importing the module I can’t use the definition\method request

when typing help(requests) I get:

>>> help(requests024)
Help on javapackage object:

requests024 = class javapackage(object)
 |  Data and other attributes defined here:
 |  
 |  __dict__ = <dictproxy object at 0x3>
 |  
 |  __dir__ = <java function __dir__ 0x5>
 |  
 |  
 |  __findattr_ex__ = <java function __findattr_ex__ 0x7>
 |  
 |  
 |  __mgr__ = <reflected field public org.python.core.packagec...ger org.p...
 |  
 |  __new__ = <built-in method __new__ of type object at 0x9>
 |      T.__new__(S, ...) -> a new object with type S, a subtype of T
 |  
 |  __setattr__ = <java function __setattr__ 0xb>
 |  
 |  
 |  addClass = <java function addClass 0xd>
 |  
 |  
 |  addPackage = <java function addPackage 0xf>
 |  
 |  
 |  addPlaceholders = <java function addPlaceholders 0x11>
 |  
 |  
 |  clsSet = <reflected field public org.python.core.PyStringMap org.pytho...
 |  
 |  fillDir = <java function fillDir 0x14>
 |  
 |  
 |  refersDirectlyTo = <java function refersDirectlyTo 0x16>
 |  
 |  
 |  toString = <java function toString 0x18>
 |  
 |  
 |  traverse = <java function traverse 0x1a>

so I understand that the module is not ready loaded correctly.

when trying to load different module , let’s say XML
and writing help(XML)

I get

>>> help(xml)
Help on package xml:

NAME
    xml - Core XML support for Jython.

FILE
    c:\users\raml\.ignition\cache\gwlocalhost_8088\c0\pylib\xml\__init__.py

DESCRIPTION
    This package contains two sub-packages:
    
    dom -- The W3C Document Object Model.  This supports DOM Level 1 +
           Namespaces.
    
    sax -- The Simple API for XML, developed by XML-Dev, led by David
           Megginson and ported to Python by Lars Marius Garshol.  This
           supports the SAX 2 API.

PACKAGE CONTENTS
    FtCore
    Uri
    dom (package)
    etree (package)
    parsers (package)
    sax (package)

DATA
    __all__ = ['dom', 'sax']

can anyone spot the issue?

thanks

Please edit your post to make it readable: highlight each section of pasted plain text and code and click the “preformatted text” button.

thank you for your comment Phil,
done.

I don’t see anything obviously wrong. Jython is built on java, so seeing java information is not a surprise. (And jython help() is not particularly helpful.) More helpful would be the backtrace you get when you try to use it and it fails. But first, make sure the version you choose is compatible with jython 2.5 (Ignition v7.9.x) or jython 2.7 (Ignition v8+). Also see this topic:

{ side note: the “3rd party modules” category is for authors of Ignition add-on modules, like me, to advertise our products. It doesn’t refer to 3rd party python modules. Consider changing the category to get wider visibility for your question. }

When trying to run requests.request(…)

requests.request(“GET”, url, headers=headers, params=querystring)

I get:

Traceback (most recent call last):
  File "<input>", line 4, in <module>
AttributeError: 'javapackage' object has no attribute 'request'

If you’re just trying to do the standard HTTP Verbs requests, why not use Ignitions built-in way system.net.httpClient system.net.httpClient - Ignition User Manual 8.0 - Ignition Documentation

client = system.net.httpClient()
 
# Sent a GET request
response = client.get("https://httpbin.org/get", params={"a": 1, "b": 2})
1 Like

Hi,
thank you for your comment.
this is actually my current solution but I would be glad the succeed with importing this module in order to understand a bit better how to work with external modules and the specific Requests module seems to be an appropriate choice as I see that some people already used it in the ignition.