Select to view content in your preferred language

making activity report by python API get the error of the specified day of the week

276
0
05-09-2023 11:54 PM
Labels (1)
MasaakiKurokawa
New Contributor III

Hello, I have made the post at the first time , thank you.

I'd like to make the weekly report of the activities by the python API.

I wrote the code below:

import datetime as dt

seven_days_ago = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=7)

def makeReport():
    global item
    user = my_gis.users.me
    #run on Monday morning
    item = user.report("activity",
    start_time=seven_days_ago,
    duration="weekly")

#run the programming function
makeReport()

 

 

and then, I got the error below:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
Cell In[5], line 3
      1 #原稿のarcgis for python api では返り値がなく、エラーを出す。ライブラリ自体も独自に修正している。
      2 #レポート作成関数の実行
----> 3 makeReport()

Cell In[4], line 6, in makeReport()
      4 user = my_gis.users.me
      5 #毎週月曜日に実行する。
----> 6 item = user.report("activity",
      7                start_time=seven_days_ago,
      8                duration="weekly")

File ~/miniforge3/envs/jnote03/lib/python3.8/site-packages/arcgis/gis/__init__.py:10474, in User.report(self, report_type, start_time, duration)
  10462 params = {
  10463     "f": "json",
  10464     "reportType": "org",
   (...)
  10467     "startTime": start_time,
  10468 }
  10470 url = "%s/sharing/rest/community/users/%s/report" % (
  10471     self._gis._url,
  10472     self._user_id,
  10473 )
> 10474 res = self._gis._con.post(url, params)
  10475 time.sleep(2)
  10476 try:

File ~/miniforge3/envs/jnote03/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py:1557, in Connection.post(self, path, params, files, **kwargs)
   1555 if return_raw_response:
   1556     return resp
-> 1557 return self._handle_response(
   1558     resp=resp,
   1559     out_path=out_path,
   1560     file_name=file_name,
   1561     try_json=try_json,
   1562     force_bytes=kwargs.pop("force_bytes", False),
   1563 )

File ~/miniforge3/envs/jnote03/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py:1027, in Connection._handle_response(self, resp, file_name, out_path, try_json, force_bytes, ignore_error_key)
   1023             return data
   1024         errorcode = (
   1025             data["error"]["code"] if "code" in data["error"] else 0
   1026         )
-> 1027         self._handle_json_error(data["error"], errorcode)
   1028     return data
   1029 else:

File ~/miniforge3/envs/jnote03/lib/python3.8/site-packages/arcgis/gis/_impl/_con/_connection.py:1052, in Connection._handle_json_error(self, error, errorcode)
   1047                 # _log.error(errordetail)
   1049 errormessage = (
   1050     errormessage + "\n(Error Code: " + str(errorcode) + ")"
   1051 )
-> 1052 raise Exception(errormessage)

Exception: Invalid startTime. Weekly report must start from Sunday or Monday.
(Error Code: 400)

I thought the reason the error is which the day of the week in the start_time , so i changed the number of the days  , 7 ~ 9 days .but , i could not get the weekly report.

seven_days_ago = dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=7)

I hope to make the report by python API. 

 

thanks , a lot 

Masaaki

0 Kudos
0 Replies