Python script problem

Hi,

I try to get my python script worling with finalbuilder 8. I have a small script that send rest api to a woordpress. 

The script is working well if executed from python 2.7. But if I execute it with final builder, the script could not find my librarie (installed from pip command. 

I have added the python lib path to the script option. The library as been installed in the c:\python27\lib\site-packages\wordpress_json

So here the script
---------------------------------------------------------------------
from wordpress_json import WordpressJsonWrapper

wp = WordpressJsonWrapper(‘http://192.168.2.89/wp-json/wp/v2’, ‘admin’, ‘password’)

wp.create_post(data=dict(title=“My title3”, content=“My content”, status=“publish”))
---------------------------------------------------------------------

The problem is that the python could not find the library

Run Script
    Status: 
      Date: 2017-01-19
      Time: 08:20:02:691
       End: 08:20:05:860
  Duration: 00:00:03:169

Action Messages:
Traceback (most recent call last):
  File “script”, line 4, in
ImportError: No module named wordpress_json


So I try to add the full path to the library  with this new path

import sys
sys.path.append(‘C:\Python27\Lib\site-packages’)

No I get this error

Run Script
    Status: 
      Date: 2017-01-19
      Time: 08:21:42:936
       End: 08:21:45:863
  Duration: 00:00:02:927

Action Messages:
Traceback (most recent call last):
  File “script”, line 4, in
  File “C:\Python27\Lib\site-packages\wordpress_json_init_.py”, line 16, in
  File “C:\Python27\Lib\site-packages\requests_init_.py”, line 52, in
  File “C:\Python27\Lib\site-packages\requests\packages_init_.py”, line 27, in
  File “C:\Python27\Lib\site-packages\requests\packages\urllib3_init_.py”, line 8, in
  File “C:\Python27\Lib\site-packages\requests\packages\urllib3\connectionpool.py”, line 11, in
  File “C:\Python27\Lib\site-packages\requests\packages\urllib3\exceptions.py”, line 2, in
  File “C:\Python27\Lib\site-packages\requests\packages\urllib3\packages\six.py”, line 701, in
  File “C:\Python27\Lib\site-packages\requests\packages\urllib3\packages\six.py”, line 692, in exec_
AttributeError: ‘module’ object has no attribute '_getframe’

I’m not an python expert, so this is now out of my knowlege. Is it possible to use the python 2.7 instead of using ironPython ?

Here the official doc

https://pypi.python.org/pypi/wordpress_json

Regards

Jonathan



Hi Jonathan,

The python script engine inside FinalBuilder is iron-python. From my understanding (I will double check with Vincent when he gets in) it will not allow the loading of libraries from pip.

The solution here is to run the script through a shell command using python directly. Inside a execute program action use the following similar command.

C:\Python27\python.exe C:\Users\Username\Desktop\my_python_script.py

where “C:\Users\Username\Desktop\my_python_script.py” is a python script file containing the script you have listed above.

Posted By Jason Smith on 19 Jan 2017 03:52 PM
Hi Jonathan,

The python script engine inside FinalBuilder is iron-python. From my understanding (I will double check with Vincent when he gets in) it will not allow the loading of libraries from pip.

The solution here is to run the script through a shell command using python directly. Inside a execute program action use the following similar command.

C:\Python27\python.exe C:\Users\Username\Desktop\my_python_script.py

where "C:\Users\Username\Desktop\my_python_script.py" is a python script file containing the script you have listed above.


Hi Jason,

How I will be able to access FinalBuilder Variable with external script ? With Environnement Variable ?

Regards

Jonathan

Hi Johnathan,

You will need to pass them as command line parameters to the python script. This is a good tutorial on how to achieve this locate at:

https://www.tutorialspoint.com/python/python_command_line_arguments.htm

When passing the variables as command line parameters you will need to quote each parameter if there are spaces in the values. For example:

python test.py “%myVar1%” “%myVar2%” “%myVar3”