Skip to main content
Solved

Python and FME Server - Unprocessable Entity error


oscard
Influencer
Forum|alt.badge.img+21

Hi.

I want to run a workspace using the Python script I have pasted here. But everytime I run it, I get the following error:

HTTP Error 422: Unprocessable Entity

My Python version is 2.7.

FME Server 2016

Thanks for any help provided!

import urllib2
import json

SERVER_URL = "http://100.100.100.100"
REPOSITORY = "MyRepo"
WORKSPACE = "First%20Test.fmw"
TOKEN = "ddddddddddddddddddddddddddddddddddddddddddddddddd"


# Set up the published parameters as object
params = {
    "publishedParameters" : [
        {
            "name" : "path_1",
            "value" : "C:\test1"
        },
        {
            "name" : "path_2",
            "value" : "C:\test2"
        }
    ]
}


url = '{0}/fmerest/v2/transformations/commands/submit/{1}/{2}'.format(SERVER_URL, REPOSITORY, WORKSPACE)

# Request constructor expects bytes, so we need to encode the string
body = json.dumps(params).encode('utf-8')

headers = {
    'Content-Type' : 'application/json',
    'Accept' : 'application/json',
    'Authorization' : 'fmetoken token={0}'.format(TOKEN)
}

# This will use POST, since we are including data
req = urllib2.Request(url, body, headers)

r = urllib2.urlopen(req)

print('Request status: ' + str(r.status))

resp = r.read()
resp = resp.decode('utf-8')
resp = json.loads(resp)

if r.status == 202:
    print('Job ID is {0}'.format(resp['id']))

Best answer by david_r

On second thought you don't need the urlencode().

There's possibility that the backslash in your path names is causing problems. Try using forward slashes:

 

params = {
    "publishedParameters" : [
        {
            "name" : "path_1",
            "value" : "C:/test1"
        },
        {
            "name" : "path_2",
            "value" : "C:/test2"
        }
    ]
} 

For reference, return code 422 means "The request was well-formed, but cannot be performed due to semantic errors." If you still get the error, make sure that your workspace does have two parameters "path_1" and "path_2" (attention to case).

View original
Did this help you find an answer to your question?

6 replies

david_r
Evangelist
  • April 7, 2017

At first glance I see a non-terminated string literal on line 19. Is that a copy-paste error?


oscard
Influencer
Forum|alt.badge.img+21
  • Author
  • Influencer
  • April 7, 2017
david_r wrote:

At first glance I see a non-terminated string literal on line 19. Is that a copy-paste error?

Yes, that's a copy-paste error. I wll edit it right away,

 

 

Thanks

 


david_r
Evangelist
  • April 7, 2017

You may have to urlencode the json string becore passing it into urllib2.Request, e.g.

import urllib
...
req = urllib2.Request(url, urllib.urlencode(body), headers)

Let me know if that makes a difference.


oscard
Influencer
Forum|alt.badge.img+21
  • Author
  • Influencer
  • April 11, 2017
david_r wrote:

You may have to urlencode the json string becore passing it into urllib2.Request, e.g.

import urllib
...
req = urllib2.Request(url, urllib.urlencode(body), headers)

Let me know if that makes a difference.

With that code I get this error:

 

 

TypeError: not a valid non-string sequence or mapping object

 


david_r
Evangelist
  • Best Answer
  • April 11, 2017

On second thought you don't need the urlencode().

There's possibility that the backslash in your path names is causing problems. Try using forward slashes:

 

params = {
    "publishedParameters" : [
        {
            "name" : "path_1",
            "value" : "C:/test1"
        },
        {
            "name" : "path_2",
            "value" : "C:/test2"
        }
    ]
} 

For reference, return code 422 means "The request was well-formed, but cannot be performed due to semantic errors." If you still get the error, make sure that your workspace does have two parameters "path_1" and "path_2" (attention to case).


oscard
Influencer
Forum|alt.badge.img+21
  • Author
  • Influencer
  • April 11, 2017
david_r wrote:

On second thought you don't need the urlencode().

There's possibility that the backslash in your path names is causing problems. Try using forward slashes:

 

params = {
    "publishedParameters" : [
        {
            "name" : "path_1",
            "value" : "C:/test1"
        },
        {
            "name" : "path_2",
            "value" : "C:/test2"
        }
    ]
} 

For reference, return code 422 means "The request was well-formed, but cannot be performed due to semantic errors." If you still get the error, make sure that your workspace does have two parameters "path_1" and "path_2" (attention to case).

Thanks to your comment I realized that path_1 is a list...

 

 

params = {
    "publishedParameters" : [
        {
            "name" : "path_1",
            "value" : ["C://test1"]
        },
        {
            "name" : "path_2",
            "value" : "C://test2"
        }
    ]
}

 

Thanks!!

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings