0
for user in comments['comment_id']:
  try:
    get_profile(user)
  except urllib.error.HTTPError:
    continue

and I have gotten error like this, I don't know how to solve this problem

<ipython-input-38-c9a67ae2e3f1> in <module>()
      2 for user in comments['comment_id']:
      3   try:
----> 4     get_profile(user)
      5   except urllib.error.HTTPError:
      6     continue

/usr/local/lib/python3.7/dist-packages/requests/models.py in raise_for_status(self)
    939 
    940         if http_error_msg:
--> 941             raise HTTPError(http_error_msg, response=self)
    942 
    943     def close(self):

HTTPError: 404 Client Error: Not Found for url: https://m.facebook.com/344608967148594/about/
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • What is `get_profile`? Is it using the `requests` module? Because it looks like you are just catching the wrong HTTPError class. – Gino Mempin Aug 13 '21 at 04:11

1 Answers1

0
for user in comments['comment_id']:
  try:
    get_profile(user)
  except:
    continue
ying li
  • 46
  • 1
  • 5
  • 1
    While this works, it catches _all_ exceptions, not just the 404 response. It's best practice to catch a _specific_ exception. – Gino Mempin Aug 13 '21 at 04:13
  • maybe you can try this: https://stackoverflow.com/questions/3193060/how-do-i-catch-a-specific-http-error-in-python I hope it helps – ying li Aug 13 '21 at 06:30