OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I am getting if 'data' in data and 'jobs' in data['data']: TypeError: argument of type 'NoneType' is not iterable this error

  • Thread starter Thread starter Vaibhavi Mendre
  • Start date Start date
V

Vaibhavi Mendre

Guest
In this project we want to fetch metadata of UID and all the metadata has to convert into csv file so I want to add timebound to json query which has to fetch data within 24 hours but I encountered this error from below code:

Code:
import json
import pandas as pd
from datetime import datetime, timedelta, timezone
end_time = datetime.now(timezone.utc)
start_time = end_time - timedelta(days=1)
end_time_str = end_time.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
start_time_str = start_time.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
 

url = 'https://api.skedulo.com/graphql/graphql'
headers = {'Content-Type': 'application/json', 'Authorization': 'your access token'}
query_1 = {
    "query": f"""
        query {{
            jobs(
                after: null,
                orderBy: "UID",
                filter: "JobStatus == 'Complete' AND ActualEnd >= '{start_time_str}' AND ActualEnd <= '{end_time_str}'"
            ) {{
                edges {{
                    cursor
                    node {{
                        UID
                        Name
                    }}
                }}
                pageInfo {{
                    hasNextPage
                }}
            }}
        }}
    """
}
response = requests.post(url, data=json.dumps(query_1), headers=headers, verify=True)
data = response.json()
print(response.content)
uids = []
if 'data' in data and 'jobs' in data['data']:
    for job in data['data']['jobs']['edges']:
        uids.append(job['node']['UID'])
else:
    print("No valid data found in the response.")
 
print(uids)```

I am getting this error from above code:
b'{"data":null,"errors":[{"message":"Expected type \'EQLQueryFilterJobs\', found \'\\"JobStatus == \\\\\\"Complete\\\\\\" AND ActualEnd >= \'2024-06-20T08:46:10.143Z\' AND ActualEnd <= \'2024-06-21T08:46:10.143Z\'\\"\'. Expected: InstantTag got StringTag (line 6, column 25):\\n                filter: \\"JobStatus == \\\\\\"Complete\\\\\\" AND ActualEnd >= \'2024-06-20T08:46:10.143Z\' AND ActualEnd <= \'2024-06-21T08:46:10.143Z\'\\"\\n                        ^","locations":[{"line":6,"column":25}]}]}'
Traceback (most recent call last):
  File "C:\Users\mendrev\Downloads\GOLD BUG POC\sampleuid.py", line 38, in <module>
    if 'data' in data and 'jobs' in data['data']:
TypeError: argument of type 'NoneType' is not iterable
has context menu
Add any details you missed and read through it again. Now is a good time to make sure that your title still describes the problem!
<p>In this project we want to fetch metadata of UID and all the metadata has to convert into csv file so I want to add timebound to json query which has to fetch data within 24 hours but I encountered this error from below code:</p>
<pre><code>import json
import pandas as pd
from datetime import datetime, timedelta, timezone
end_time = datetime.now(timezone.utc)
start_time = end_time - timedelta(days=1)
end_time_str = end_time.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'
start_time_str = start_time.strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'


url = 'https://api.skedulo.com/graphql/graphql'
headers = {'Content-Type': 'application/json', 'Authorization': 'your access token'}
query_1 = {
"query": f"""
query {{
jobs(
after: null,
orderBy: "UID",
filter: "JobStatus == 'Complete' AND ActualEnd >= '{start_time_str}' AND ActualEnd <= '{end_time_str}'"
) {{
edges {{
cursor
node {{
UID
Name
}}
}}
pageInfo {{
hasNextPage
}}
}}
}}
"""
}
response = requests.post(url, data=json.dumps(query_1), headers=headers, verify=True)
data = response.json()
print(response.content)
uids = []
if 'data' in data and 'jobs' in data['data']:
for job in data['data']['jobs']['edges']:
uids.append(job['node']['UID'])
else:
print("No valid data found in the response.")

print(uids)```

I am getting this error from above code:
b'{"data":null,"errors":[{"message":"Expected type \'EQLQueryFilterJobs\', found \'\\"JobStatus == \\\\\\"Complete\\\\\\" AND ActualEnd >= \'2024-06-20T08:46:10.143Z\' AND ActualEnd <= \'2024-06-21T08:46:10.143Z\'\\"\'. Expected: InstantTag got StringTag (line 6, column 25):\\n filter: \\"JobStatus == \\\\\\"Complete\\\\\\" AND ActualEnd >= \'2024-06-20T08:46:10.143Z\' AND ActualEnd <= \'2024-06-21T08:46:10.143Z\'\\"\\n ^","locations":[{"line":6,"column":25}]}]}'
Traceback (most recent call last):
File "C:\Users\mendrev\Downloads\GOLD BUG POC\sampleuid.py", line 38, in <module>
if 'data' in data and 'jobs' in data['data']:
TypeError: argument of type 'NoneType' is not iterable
has context menu
Add any details you missed and read through it again. Now is a good time to make sure that your title still describes the problem!
</code></pre>
 

Latest posts

I
Replies
0
Views
1
Isaac P. Liu
I
U
Replies
0
Views
1
user3658366
U
G
Replies
0
Views
1
Giampaolo Levorato
G
M
Replies
0
Views
1
Marcelo Rodrigo Nascimento
M
Top