1

I have an sql query that's returning the following value -

{'jobrun_deps': 'T=1 \x01ID=56494759 \x01DID=583887 \x01O=N \x01M=N \x01J=76732 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494760 \x01DID=418400 \x01O=N \x01M=N \x01J=48064 \x01R=14780471 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494761 \x01DID=583889 \x01O=N \x01M=N \x01J=76733 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01'}

So when I try to do this -

results = (re.findall(r'ID=(\d+)', my_query))

I get this error -

Traceback (most recent call last):
  File "D:\Scripts\OPS\TIDAL\dependency_check.py", line 25, in <module>
    results = (re.findall(r'ID=(\d+)', my_query))
  File "D:\Python27\lib\re.py", line 177, in findall
    return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer

This is because the re.findall is expecting it to not have the column name in the results. how do I either change my re.findall to use the output I'm providing or change the sql query to give a string like it expects.

'T=1 \x01ID=56494759 \x01DID=583887 \x01O=N \x01M=N \x01J=76732 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494760 \x01DID=418400 \x01O=N \x01M=N \x01J=48064 \x01R=14780471 \x01P=1 \x01S=101 \x01WR=N \x01T=1 \x01ID=56494761 \x01DID=583889 \x01O=N \x01M=N \x01J=76733 \x01R=0 \x01P=1 \x01S=101 \x01WR=N \x01'

1 Answer 1

3

Its because of that my_query is a dictionary and you can not pass it to re.findall you need to pass the value of the dictionary :

results = (re.findall(r'ID=(\d+)', my_query['jobrun_deps']))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! knew it was going to be something simple.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.