AttributeError: 'NoneType' object has no attribute 'is_lightning'

Crash Report
============

This crash report was reported through the automatic crash reporting system 🤖

Traceback
--------------

```Python traceback
  File "electrum\\gui\\qt\\main_window.py", line 1103, in <lambda>
  File "electrum\\gui\\qt\\main_window.py", line 1220, in create_invoice

AttributeError: 'NoneType' object has no attribute 'is_lightning'
```

Reporter
------------

This issue was reported by 16 user(s):

| Electrum Version  | Python Version | Operating System  | Wallet Type  | Locale | Stack |
|---|---|---|---|---|---|
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.18362-SP0 | imported | de_DE | [ℹ](https://crashhub.electrum.org//crash/13055) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.18362-SP0 | imported | de_DE | [ℹ](https://crashhub.electrum.org//crash/13056) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.18362-SP0 | imported | en_US | [ℹ](https://crashhub.electrum.org//crash/13073) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.16299-SP0 | standard | en_US | [ℹ](https://crashhub.electrum.org//crash/13079) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.16299-SP0 | standard | en_US | [ℹ](https://crashhub.electrum.org//crash/13080) | 
| 4.0.1  | 3.7.7 (default, Jun 23 2020, 16:29:54)  [Clang 11.0.0 (clang-1100.0.33.17)] | Darwin-17.7.0-x86_64-i386-64bit | imported | ? | [ℹ](https://crashhub.electrum.org//crash/13089) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.19041-SP0 | imported | bg_BG | [ℹ](https://crashhub.electrum.org//crash/13099) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-7-6.1.7601-SP1 | imported | bg_BG | [ℹ](https://crashhub.electrum.org//crash/13118) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-7-6.1.7601-SP1 | imported | bg_BG | [ℹ](https://crashhub.electrum.org//crash/13119) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.18362-SP0 | imported | en_GB | [ℹ](https://crashhub.electrum.org//crash/13129) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.18362-SP0 | standard | ru_RU | [ℹ](https://crashhub.electrum.org//crash/13136) | 
| 4.0.1  | 3.7.7 (default, Jun 23 2020, 16:29:54)  [Clang 11.0.0 (clang-1100.0.33.17)] | Darwin-19.5.0-x86_64-i386-64bit | imported | ? | [ℹ](https://crashhub.electrum.org//crash/13489) | 
| 4.0.4  | 3.7.9 (default, Sep 11 2020, 17:18:37)  [Clang 11.0.0 (clang-1100.0.33.17)] | Darwin-19.6.0-x86_64-i386-64bit | imported | ? | [ℹ](https://crashhub.electrum.org//crash/15597) | 
| 4.0.9  | 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:01:55) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.20270-SP0 | standard | el_GR | [ℹ](https://crashhub.electrum.org//crash/16442) | 
| 4.1.5  | 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit (Intel)] | Windows-10-10.0.19041-SP0 | imported | en_US | [ℹ](https://crashhub.electrum.org//crash/21343) | 
| 4.0.1  | 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 09:44:33) [MSC v.1900 32 bit (Intel)] | Windows-10-10.0.19041-SP0 | imported,standard | fr_BF | [ℹ](https://crashhub.electrum.org//crash/25658) | 


Additional Information
------------------------


> 1GuxVaa3QqeyXGc13MFzmasMRK7HZwbA18

---


> 1GuxVaa3QqeyXGc13MFzmasMRK7HZwbA18

---


> Have imported three private keys. Want to receive funds. Click request and it complains about keys. Ideally it would ask me which public key into which I wish to receive funds.

---


diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
index a2979e6b9..cc0ab0f86 100644
--- a/electrum/gui/qt/main_window.py
+++ b/electrum/gui/qt/main_window.py
@@ -1209,7 +1209,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
             key = self.wallet.lnworker.add_request(amount, message, expiry)
         else:
             key = self.create_bitcoin_request(amount, message, expiry)
+            if not key:
+                return
             self.address_list.update()
+        assert key is not None
         self.request_list.update()
         self.request_list.select_key(key)
         # clear request fields
@@ -1221,20 +1224,23 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
         title = _('Invoice') if is_lightning else _('Address')
         self.do_copy(content, title=title)
 
-    def create_bitcoin_request(self, amount, message, expiration):
+    def create_bitcoin_request(self, amount, message, expiration) -> Optional[str]:
         addr = self.wallet.get_unused_address()
         if addr is None:
-            if not self.wallet.is_deterministic():
+            if not self.wallet.is_deterministic():  # imported wallet
                 msg = [
-                    _('No more addresses in your wallet.'),
-                    _('You are using a non-deterministic wallet, which cannot create new addresses.'),
-                    _('If you want to create new addresses, use a deterministic wallet instead.')
+                    _('No more addresses in your wallet.'), ' ',
+                    _('You are using a non-deterministic wallet, which cannot create new addresses.'), ' ',
+                    _('If you want to create new addresses, use a deterministic wallet instead.'), '\\n\\n',
+                    _('Creating a new payment request will reuse one of your addresses and overwrite an existing request. Continue anyway?'),
                    ]
-                self.show_message(' '.join(msg))
-                return
-            if not self.question(_("Warning: The next address will not be recovered automatically if you restore your wallet from seed; you may need to add it manually.\\n\\nThis occurs because you have too many unused addresses in your wallet. To avoid this situation, use the existing addresses first.\\n\\nCreate anyway?")):
-                return
-            addr = self.wallet.create_new_address(False)
+                if not self.question(''.join(msg)):
+                    return
+                addr = self.wallet.get_receiving_address()
+            else:  # deterministic wallet
+                if not self.question(_("Warning: The next address will not be recovered automatically if you restore your wallet from seed; you may need to add it manually.\\n\\nThis occurs because you have too many unused addresses in your wallet. To avoid this situation, use the existing addresses first.\\n\\nCreate anyway?")):
+                    return
+                addr = self.wallet.create_new_address(False)
         req = self.wallet.make_payment_request(addr, amount, message, expiration)
         try:
             self.wallet.add_payment_request(req)
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
index 8288128a4..da7c471c8 100644
--- a/electrum/lnworker.py
+++ b/electrum/lnworker.py
@@ -1123,7 +1123,7 @@ class LNWallet(LNWorker):
         route[-1].node_features |= invoice_features
         return route
 
-    def add_request(self, amount_sat, message, expiry):
+    def add_request(self, amount_sat, message, expiry) -> str:
         coro = self._add_request_coro(amount_sat, message, expiry)
         fut = asyncio.run_coroutine_threadsafe(coro, self.network.asyncio_loop)
         try:
@@ -1158,7 +1158,7 @@ class LNWallet(LNWorker):
         self.save_payment_info(info)
         return lnaddr, invoice
 
-    async def _add_request_coro(self, amount_sat: Optional[int], message, expiry: int):
+    async def _add_request_coro(self, amount_sat: Optional[int], message, expiry: int) -> str:
         lnaddr, invoice = await self.create_invoice(amount_sat, message, expiry)
         key = bh2u(lnaddr.paymenthash)
         req = LNInvoice.from_bech32(invoice)
['electrum/lnworker.py', 'electrum/gui/qt/main_window.py']