Repository: praw-dev/praw

Issue:
praw 7.1.1 no longer works with Python 3.6: module 'asyncio' has no attribute 'get_running_loop'
**Describe the bug**

Using praw 7.1.1 with Python 3.6 fails with `module 'asyncio' has no attribute 'get_running_loop'`, even though 3.6 is a supported version according to `setup.py`.

Downgrading to 7.1.0 resolves the issue, however the following message is displayed when the `praw.Reddit` object is created: `Version 7.1.0 of praw is outdated. Version 7.1.1 was released 6 hours ago.`.

**To Reproduce**

With Python 3.6:

```
import praw
p = praw.Reddit(client_id="-", client_secret="-", user_agent="-")
p.redditor("globau").fullname
```

**Expected behaviour**

```
t2_4ptgi
```

**Actual behaviour**

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/../venv/lib64/python3.6/site-packages/praw/models/reddit/base.py", line 34, in __getattr__
    self._fetch()
  File "/../venv/lib64/python3.6/site-packages/praw/models/reddit/redditor.py", line 170, in _fetch
    data = self._fetch_data()
  File "/../venv/lib64/python3.6/site-packages/praw/models/reddit/redditor.py", line 167, in _fetch_data
    return self._reddit.request("GET", path, params)
  File "/../venv/lib64/python3.6/site-packages/praw/reddit.py", line 793, in request
    self._check_for_async()
  File "/../venv/lib64/python3.6/site-packages/praw/reddit.py", line 371, in _check_for_async
    asyncio.get_running_loop()
AttributeError: module 'asyncio' has no attribute 'get_running_loop'
```

**System Info**
 - OS: CentOS 8.1
 - Python: Python 3.6.8
 - PRAW Version: 7.1.1



Discussion:
This was introduced by @LilSpazJoekp in cd8ab625c88d14efb18f961d1365a8dce1a121e9.

A workaround is to disable the async check with `praw.Reddit(..., check_for_async=False)`.

Perhaps this check should be skipped on Python 3.6?  `asyncio.get_event_loop()` isn't a good alternative as it will create a new event loop.
Side note: interesting that CI didn't catch this; I see 3.6 in the list of Python versions.
> Side note: interesting that CI didn't catch this; I see 3.6 in the list of Python versions.

This is very interesting as it should have caught it. Nonetheless, it is my fault for not ensuring that method is available on all supported Python versions.

Like you said, the work around for this is to pass `check_async=False` or to update to ≥Python 3.7. 

Thanks for catching this! I will be fixing this shortly.

Resolving patch:
diff --git a/praw/reddit.py b/praw/reddit.py
--- a/praw/reddit.py
+++ b/praw/reddit.py
@@ -3,6 +3,7 @@
 import configparser
 import os
 import re
+import sys
 import time
 from itertools import islice
 from logging import getLogger
@@ -367,11 +368,16 @@ def request(self, *args, **kwargs):
 
     def _check_for_async(self):
         if self.config.check_for_async:
-            try:
-                asyncio.get_running_loop()
-            except RuntimeError:
-                pass
-            else:
+            in_async = False
+            if sys.version_info >= (3, 7, 0):
+                try:
+                    asyncio.get_running_loop()
+                    in_async = True
+                except RuntimeError:
+                    pass
+            else:  # pragma: no cover # not able to be covered in > Python 3.6.12
+                in_async = asyncio.get_event_loop().is_running()
+            if in_async:
                 logger.warning(
                     "It appears that you are using PRAW in an asynchronous"
                     " environment.\nIt is strongly recommended to use Async PRAW:"


Test patch:
diff --git a/tests/integration/models/reddit/test_modmail.py b/tests/integration/models/reddit/test_modmail.py
--- a/tests/integration/models/reddit/test_modmail.py
+++ b/tests/integration/models/reddit/test_modmail.py
@@ -1,3 +1,4 @@
+import sys
 from datetime import datetime
 from unittest import mock
 
@@ -42,9 +43,19 @@ def test_mute_duration(self, _):
             conversation.mute(7)
             conversation = self.reddit.subreddit("all").modmail("g46rw")
             assert conversation.user.mute_status["isMuted"]
-            diff = datetime.fromisoformat(
-                conversation.user.mute_status["endDate"]
-            ) - datetime.fromisoformat(conversation.mod_actions[-1].date)
+            if sys.version_info >= (3, 7, 0):
+                diff = datetime.fromisoformat(
+                    conversation.user.mute_status["endDate"]
+                ) - datetime.fromisoformat(conversation.mod_actions[-1].date)
+            else:
+                end_date = "".join(
+                    conversation.user.mute_status["endDate"].rsplit(":", 1)
+                )
+                start_date = "".join(conversation.mod_actions[-1].date.rsplit(":", 1))
+                date_format = "%Y-%m-%dT%H:%M:%S.%f%z"
+                diff = datetime.strptime(end_date, date_format) - datetime.strptime(
+                    start_date, date_format
+                )
             assert diff.days == 6  # 6 here because it is not 7 whole days
 
     @mock.patch("time.sleep", return_value=None)