jcsalterego / Constantine

Constantine helps you find your posts in the Hellthread.
Other
9 stars 25 forks source link

delete_hellthreads.py errors out #4

Closed StuBlad closed 1 year ago

StuBlad commented 1 year ago

I succesfully setup a local copy of Constantine in WSL2 and was able to use get_helltheads.py just fine but when i call delete_hellthreads.py stublad.renoproject.org, it attempts to delete a post and then dies.

I'm using WSL2 and Python 3.10.6.

Here's the output:


Stu@StuLaptop:~/Constantine$ ./delete_hellthreads.py stublad.renoproject.org
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
1135 posts total
80 hellthread posts total
Deleting https://bsky.app/profile/<scrubbed>
Traceback (most recent call last):
  File "/home/Stu/.local/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 142, in <module>
    main()
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 128, in main
    results = delete_post(session, uri)
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 95, in delete_post
    return post_xrpc(session, "com.atproto.repo.deleteRecord", json=json)
  File "/home/Stu/Constantine/constantine.py", line 58, in post_xrpc
    return response.json()
  File "/home/Stu/.local/lib/python3.10/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)```
jcsalterego commented 1 year ago

Thanks for the stacktrace. I've pushed a code change that will show the entire error. Can you try again and share what it says?

mattstratton commented 1 year ago

I have the most recent version and getting this:

cursor = 1682885319815::bafyreic7u3ccopzjqcjokgzbeacvli2hnakjwekoqfrwkbfihrbv3yfko4
13392 posts total
12641 hellthread posts total
Deleting https://bsky.app/profile/did:plc:*****
Traceback (most recent call last):
  File "/Users/matty.stratton/src/github.com/jcsalterego/Constantine/./delete_hellthreads.py", line 137, in <module>
    main()
  File "/Users/matty.stratton/src/github.com/jcsalterego/Constantine/./delete_hellthreads.py", line 128, in main
    delete_post(session, uri)
  File "/Users/matty.stratton/src/github.com/jcsalterego/Constantine/./delete_hellthreads.py", line 95, in delete_post
    return post_xrpc(session, "com.atproto.repo.deleteRecord", json=json)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/matty.stratton/src/github.com/jcsalterego/Constantine/constantine.py", line 56, in post_xrpc
    text = response.text()
           ^^^^^^^^^^^^^^^
TypeError: 'str' object is not callable

( redacted the DID for privacy)

jcsalterego commented 1 year ago

@mattstratton Thanks for testing. Embarrassing code change on my part. Can you give it a shot again?

StuBlad commented 1 year ago

@jcsalterego Hey. I pulled the latest commit and got this:

Stu@StuLaptop:~/Constantine$ ./delete_hellthreads.py stublad.renoproject.org
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
cursor = <scrubbed>
1171 posts total
79 hellthread posts total
Deleting https://bsky.app/profile/<scrubbed>
Traceback (most recent call last):
  File "/home/Stu/Constantine/constantine.py", line 58, in post_xrpc
    return json.loads(text)
AttributeError: 'dict' object has no attribute 'loads'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 137, in <module>
    main()
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 128, in main
    delete_post(session, uri)
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 95, in delete_post
    return post_xrpc(session, "com.atproto.repo.deleteRecord", json=json)
  File "/home/Stu/Constantine/constantine.py", line 59, in post_xrpc
    except json.JSONDecodeError:
AttributeError: 'dict' object has no attribute 'JSONDecodeError'
mmarchini commented 1 year ago

yeah I got that too. The following patch (or something similar) fixes it:

diff --git a/constantine.py b/constantine.py
index 0d95543..ab68dea 100755
--- a/constantine.py
+++ b/constantine.py
@@ -46,10 +46,10 @@ def get_xrpc(session, endpoint, params={}):
     return response.json()

-def post_xrpc(session, endpoint, json={}):
+def post_xrpc(session, endpoint, jsonBody={}):
     response = requests.post(
         f"https://bsky.social/xrpc/{endpoint}",
-        json=json,
+        json=jsonBody,
         headers={"Authorization": f"Bearer {session['accessJwt']}"},
     )
     if response.status_code == 200:
diff --git a/delete_hellthreads.py b/delete_hellthreads.py
index b264998..1b39622 100755
--- a/delete_hellthreads.py
+++ b/delete_hellthreads.py
@@ -92,7 +92,7 @@ def delete_post(session, uri):
             "repo": did,
             "rkey": rkey,
         }
-        return post_xrpc(session, "com.atproto.repo.deleteRecord", json=json)
+        return post_xrpc(session, "com.atproto.repo.deleteRecord", jsonBody=json)
     return None
StuBlad commented 1 year ago

yeah I got that too. The following patch (or something similar) fixes it:

diff --git a/constantine.py b/constantine.py
index 0d95543..ab68dea 100755
--- a/constantine.py
+++ b/constantine.py
@@ -46,10 +46,10 @@ def get_xrpc(session, endpoint, params={}):
     return response.json()

-def post_xrpc(session, endpoint, json={}):
+def post_xrpc(session, endpoint, jsonBody={}):
     response = requests.post(
         f"https://bsky.social/xrpc/{endpoint}",
-        json=json,
+        json=jsonBody,
         headers={"Authorization": f"Bearer {session['accessJwt']}"},
     )
     if response.status_code == 200:
diff --git a/delete_hellthreads.py b/delete_hellthreads.py
index b264998..1b39622 100755
--- a/delete_hellthreads.py
+++ b/delete_hellthreads.py
@@ -92,7 +92,7 @@ def delete_post(session, uri):
             "repo": did,
             "rkey": rkey,
         }
-        return post_xrpc(session, "com.atproto.repo.deleteRecord", json=json)
+        return post_xrpc(session, "com.atproto.repo.deleteRecord", jsonBody=json)
     return None

I applied the patch you shared and get this stack trace:

Traceback (most recent call last):
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 137, in <module>
    main()
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 128, in main
    delete_post(session, uri)
  File "/home/Stu/Constantine/./delete_hellthreads.py", line 95, in delete_post
    return post_xrpc(session, "com.atproto.repo.deleteRecord", jsonBody=json)
TypeError: post_xrpc() got an unexpected keyword argument 'jsonBody'
jcsalterego commented 1 year ago

Thanks @mmarchini for the patch. Thanks @StuBlad @mattstratton for testing. I'll get this fixed later today. I'm a dummy!

jcsalterego commented 1 year ago

Hi all, thanks for your patience. We should be good now - please try the latest.

Thanks again to @mmarchini for pointing out that I was shadowing json 🤦‍♂️

mattstratton commented 1 year ago

It’s working for me now! Thank you!!!

StuBlad commented 1 year ago

I can confirm this fixed it for me too. Thanks everyone! Closing this issue out.

jcsalterego commented 1 year ago

Thanks all