# RC76xx HTTP Connection via PySerial

**URL:** <https://forum.sierrawireless.com/t/rc76xx-http-connection-via-pyserial/33973>\
**Category:** RC76\
**Created:** [November 10, 2024, 5:21pm UTC](https://forum.sierrawireless.com/t/rc76xx-http-connection-via-pyserial/33973 "2024-11-10T17:21:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtanadi](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jtanadi](https://forum.sierrawireless.com/u/jtanadi)\
**Post date:** [November 10, 2024, 5:21pm UTC](https://forum.sierrawireless.com/t/rc76xx-http-connection-via-pyserial/33973/1 "2024-11-10T17:21:28Z")

</div>

Hi all, I’m having some issues making HTTP connections in Python (via the serial module) and I’m not sure why—I keep on getting the “5—HTTP connection error due to internal trouble” error.

I’ve had success running the following AT commands outside of Python, even though I get some errors in response:

```auto
AT+CGACT=1,3

AT+KCNXFG=3,"GPRS","nimblink.gw12.vzwentp"

AT+KHTTPCFG=3,"www.dweet.io",80
OK

+KCNX_IND: 3,4,1
+KCNX_IND: 3,1,0
+KHTTP_IND: 1,1
+KCNX_IND: 3,5, 30
+KHTTP_ERROR: 1, 5
+KHTTP_IND: 1,0
+KCNX_IND: 3,3
+KCNX_IND: 3, 0, 0

AT+KHTTPCNX=1

+KCNX_IND: 3,4,1
+KCNX_IND: 3,1,0
+KHTTP_IND: 1,1
+KCNX_IND: 3,5, 30
+KHTTP_ERROR: 1, 5
+KHTTP_IND: 1,0

AT+KHTTPGET=1,"/dweet/for/my-thing?hello=world"
CONNECT
...
+KHTTP_IND: 1, 3, 387, 200, "OK"
+KCNX_IND: 3, 5, 30
+KHTTP_ERROR: 1, 5
+KHTTP_IND: 1, 0

```

I’m not sure why I keep on getting the `KHTTP 5` error and then the modem would indicate a successful connection afterwards. In general I’ve been able to execute AT commands through Python’s serial module, but repeating the same AT commands in Python somehow isn’t working.

```auto
import serial
s = serial.Serial("/dev/ttyUSB0", ...)
s.write('AT+CGACT=1,3\r'.encode())
s.write('AT+KCNXFG=3,"GPRS","nimblink.gw12.vzwentp"\r'.encode())
s.write('AT+KHTTPCFG=3,"www.dweet.io",80\r'.encode())
...

```

Usually the error happens when I try to configure the HTTP connection; the modem would try a couple of times, but I typically end up with

```auto
KHTTP_ERROR: 1,5

```

but it never goes anywhere beyond that.

Any help or pointers would be appreciated!

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/jyijyi/32/4766_2.png) [@jyijyi](https://forum.sierrawireless.com/u/jyijyi)\
**Post date:** [November 10, 2024, 5:58pm UTC](https://forum.sierrawireless.com/t/rc76xx-http-connection-via-pyserial/33973/2 "2024-11-10T17:58:02Z")

</div>

You can try to same command as mine to use profile 1:

```auto
AT+KCNXCFG=1,"GPRS","CMHK"
OK
AT+KCNXPROFILE=1
OK
AT+KHTTPCFG=1,"www.google.com",80,0,,,,,0

+KHTTPCFG: 1

OK

+KCNX_IND: 1,4,1

+KCNX_IND: 1,1,0

+KHTTP_IND: 1,1

AT+KHTTPGET=1,"/index.html"
CONNECT
HTTP/1.1 200 OK
date: Thu, 23 Nov 2023 11:18:31 GMT
expires: -1
cache-control: private, max-age=0
content-type: text/html; charset=ISO-8859-1
content-security-policy-report-only: object-src 'none';base-uri 'self';script-src 'nonce-uF_ycRR8sT-Xv0t1Qv5DMg' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
set-cookie: 1P_JAR=2023-11-23-11; expires=Sat, 23-Dec-2023 11:18:31 GMT; path=/; domain=.google.com; Secure

NO CARRIER

+KCNX_IND: 1,5,30

+KHTTP_ERROR: 1,5

at+khttpclose=1

+CME ERROR: 922

at+khttpdel=1
OK

+KCNX_IND: 1,3

+KCNX_IND: 1,0,0

```

---

<div class="post-metadata">

**Author:** ![jtanadi](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jtanadi](https://forum.sierrawireless.com/u/jtanadi)\
**Post date:** [November 10, 2024, 7:04pm UTC](https://forum.sierrawireless.com/t/rc76xx-http-connection-via-pyserial/33973/3 "2024-11-10T19:04:30Z")

</div>

Thanks for the response. Running `AT+KCNXPROFILE` didn’t seem to fix it, but also now I seem to be running into errors when trying to start an HTTP connection even with the AT command without Python, which previously worked.

---

<div class="post-metadata">

**Author:** ![jyijyi](https://sea1.discourse-cdn.com/flex025/user_avatar/forum.sierrawireless.com/jyijyi/32/4766_2.png) [@jyijyi](https://forum.sierrawireless.com/u/jyijyi)\
**Post date:** [November 11, 2024, 1:04am UTC](https://forum.sierrawireless.com/t/rc76xx-http-connection-via-pyserial/33973/4 "2024-11-11T01:04:26Z")

</div>

Could it be sim card or network issue?

---

<div class="post-metadata">

**Author:** ![jtanadi](https://avatars.discourse-cdn.com/v4/letter/j/f04885/32.png) [@jtanadi](https://forum.sierrawireless.com/u/jtanadi)\
**Post date:** [November 11, 2024, 2:51am UTC](https://forum.sierrawireless.com/t/rc76xx-http-connection-via-pyserial/33973/5 "2024-11-11T02:51:42Z")

</div>

I tried a few different things and somehow landed at a working solution where I detach and then re-attach the packet service with `AT+CGATT=0` then `AT+CGATT=1`. The odd thing is that after activating the PDP context (with `AT+CGACT=1,3`) the packet service is already attached, hence the need to detach before re-attaching.

So the sequence that ended up working (multiple times) is

```auto
AT+CGACT=1,3
AT+KCNXCFG=3,"GPRS","nimblink.gw12.vzwentp"
AT+CGATT=0
AT+CGATT=1
(wait for OK)
AT+KHTTPCFG=3,"dweet.io",80
AT+KHTTPGET=1,...

```

This works both in Python and through plain AT commands. One other thing to note is that after the detach/re-attach procedure, the responses I get after `AT+KHTTPCFG` seem to be shorter—the modem only needs to make 1 attempt and is then able to connect.
