Skip to main content
Question

302 when using the Python API

  • May 20, 2025
  • 3 replies
  • 79 views

Hello!
I hadn’t touched my code for a week or two, and running it again I found that it didn’t work anymore. I went back to almost one of the examples from the official repository:

from censys.search import CensysHosts

if __name__ == "__main__":
api_id = "XXX"
api_secret = "YYY"

h = CensysHosts(api_id, api_secret)

query = h.search("services.service_name: FTP", per_page=1, pages=2)
all_hosts = query.view_all()
print(all_hosts)

And I’m still encountering an exception:

Traceback (most recent call last):
File "[...]\debug.py", line 10, in <module>
all_hosts = query.view_all()
^^^^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\censys\search\v2\api.py", line 208, in view_all
for hit in self.__call__():
^^^^^^^^^^^^^^^
File "[...]\.venv\Lib\site-packages\censys\search\v2\api.py", line 168, in __call__
self.total = result["total"]
~~~~~~^^^^^^^^^
TypeError: string indices must be integers, not 'str'

While debugging, I see that the “payload” variable in the Censys code contains something like “302 Moved to”, but I can’t get the corresponding location. Or could it be a problem with my credentials?
Is this Python library still supported? I see there’s a new one, but the doc says that the API isn’t stable yet, so I’m really reluctant to switch to that.

Any help would be appreciated!

3 replies

MattK_Censys
Forum|alt.badge.img+2
  • Censys Community Manager
  • May 21, 2025

Hey there, I ran this by the team. We were able to successfully run the code you provided without errors. Could you try it again and let me know if you still run into an error?


  • Author
  • New Participant
  • May 21, 2025

Hi! I got word that the Censys account we were using was killed. We’re trying to get that resolved, but there’s still an opportunity for better error handling in the library!


MattK_Censys
Forum|alt.badge.img+2
  • Censys Community Manager
  • May 21, 2025

Oh, ok! Let me know if you need assistance with that and if you run into any more issues down the road.