Giter VIP home page Giter VIP logo

huawei-modem-python-api-client's People

Contributors

aleixdev avatar axylo avatar dopstar avatar kernelport avatar mcsarge avatar mkotek avatar pablo avatar rudignet avatar tatomoaki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

huawei-modem-python-api-client's Issues

Receiving SMS in Russian

Hi. I'm trying to get an sms

import huaweisms.api.user
import huaweisms.api.sms
ctx = huaweisms.api.user.quick_login("admin", "password")
print(ctx)
smss = huaweisms.api.sms.get_sms(ctx, box_type=1, qty=1, unread_preferred=True)
print(smss)

The SMS comes and I see unknown characters in the "Content" field

<ApiCtx modem_host=192.168.8.1> {'type': 'response', 'response': {'Count': '1', 'Messages': {'Message': [{'Smstat': '0', 'Index': '40021', 'Phone': '+79992314505', 'Content': 'Ð\x9fÑ\x80ивеÑ\x82', 'Date': '2022-03-11 14:18:04', 'Sca': '', 'SaveType': '0', 'Priority': '0', 'SmsType': '1'}]}}}

Remove hard deps on certifi and chardet

Hi,
In the project's requirements.txt there are hard dependencies on certifi and chardet on some old versions, those packages aren't used anywhere in the library, they're just indirect dependencies and are probably in requirements.txt because someone did a pip freeze.
At a quick glance a correct requirements.txt for this project would just be:

requests>=2.25.1
six>=1.15.0
typing>=3.7.4.3

Problem getting messages

Hello, when I try to get the list of sms with the method sms.get_sms always I receive only one, even if I set the qty to 20, the field count mark the total number of messages but the list of messages show only one, and not always the same, the box of both messages is the same, I think is a problem with the treatment of the response because using the web interface sms-list return an xml with all the messages..

Thank you

An Example:

{'type': 'response', 'response': {'Messages': {'Message': [{'Content': 'Test message', 'Sca': '', 'Priority': '0', 'Phone': '+34600123456', 'SaveType': '4', 'Smstat': '1', 'SmsType': '1', 'Index': '40000', 'Date': '2019-09-01 04:17:45'}]}, 'Count': '2'}}

Change the SenderID

Hello Team,
I am still a novice and I just discovered this project, I would like to know if it is possible to change the senderID of the SMS sending.
Example : Server1 instead of +1XXXXXXXXX
If someone has already, edited his code to add this functionality, I am very interested.
Thank you very much

MMS Message causes program to crash

I've noticed when MMS messages are received, the program crashes with

Traceback (most recent call last):
  File "huaweiApi.py", line 52, in <module>
    latestMessage=huaweisms.api.sms.get_sms(ctx,1,1,1)
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/api/sms.py", line 39, in get_sms
    r = post_to_url(url, xml_data, ctx, headers)
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/api/common.py", line 114, in post_to_url
    return api_response(r)
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/api/common.py", line 74, in api_response
    xmldoc = parse_xml_string(r.text.encode('ascii','ignore').decode('utf-8'))
  File "/home/christopher/.local/lib/python3.8/site-packages/huaweisms/xml/util.py", line 62, in parse_xml_string
    return minidom.parseString(parseable_xml_string)
  File "/usr/lib/python3.8/xml/dom/minidom.py", line 1969, in parseString
    return expatbuilder.parseString(string)
  File "/usr/lib/python3.8/xml/dom/expatbuilder.py", line 925, in parseString
    return builder.parseString(string)
  File "/usr/lib/python3.8/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 9, column 12

I did a bit of investigation, and it seems that when an MMS message is received by the Huawei device, the API returns invalid characters. I made a really hacky fix by changing the following line in api/common.py: xmldoc = parse_xml_string(r.text) to xmldoc = parse_xml_string(r.text.encode('ascii','ignore').decode('utf-8').replace("\x01\x06\x08\x01","")) in order to remove the invalid characters, but I'm sure a better solution is out there.

The device is a Huawei B315 if it makes any difference.

E8372h-320 (not working) vs E8372h-153 (working)

Hi,
I work with both modems. The new Revision E8372h-320 is able to connect with ipv6 and ipv4.
But sending SMS produce this error:
{'type': 'error', 'error': {'code': '100005', 'message': ''}}
With the E8372h-153 I get:
{'type': 'response', 'response': 'OK'}
Sending SMS ist possible over the webinterface.
Where is the error code 100005 documented?
Regards,
Frank

Select Profile Management

Hello !

Do you think it is possible to select profile management (in settings/Dial-UP menu) in order to select APN from py scripts?

Thanks.

No handlers could be found for logger "huaweisms.api.webserver"

Hi, I'm trying to use the api for a personal project and I have run into an issue.
I have my rpi update to the latest official release and the api is also updated to v 1.0.9

Here is a snapshot of the error I am getting. Note: I added in a print statement for the token.
I would really appreciate some assistance as I am only a noob with python. Thank-you

Returned msg after code executed:
No handlers could be found for logger "huaweisms.api.webserver"
{'type': 'response', 'response': {u'SesInfo': u'SessionID=+xM3wVclSzX0+no96LTkVG+ESdhvg3AQtx6CcxwWDS6zz/E9eaKUczA/MQN1YoGuc+F2a1Du3rVpSVQ2lJRGU+rL1XRPZ9PzBMEZhaap8r/xXcrZR1FHAbKmeT/DqETP', u'TokInfo': u'RIYBy19K1/drOzCcmp/rC191uQ2Sqm02'}}
+xM3wVclSzX0+no96LTkVG+ESdhvg3AQtx6CcxwWDS6zz/E9eaKUczA/MQN1YoGuc+F2a1Du3rVpSVQ2lJRGU+rL1XRPZ9PzBMEZhaap8r/xXcrZR1FHAbKmeT/DqETP
Traceback (most recent call last):
File "CmdRequest.py", line 42, in
ctx = get_session()
File "CmdRequest.py", line 38, in get_session
lgn = user.login(ctx, user_name, password)
File "/usr/local/lib/python2.7/dist-packages/huaweisms/api/user.py", line 40, in login
password_value = b64_sha256(user_name + b64_sha256(password) + ctx.login_token)
TypeError: coercing to Unicode: need string or buffer, NoneType found

How do you use ussd

I'm just getting a response OK, I'm not able to display the ussd response

Band Selection

More of a feature request, is there a possibility for band selection to be implemented here? It would be super helpful!

Thanks :)

GET SMS

How to get sms from inbox?

ctx = get_session()
sent = sms.get_sms(ctx)
print(sent)

get_sms: get information from boxes: inbox, outbox

Sending sms in russian (utf-8) does not work

#!/usr/bin/python3

import huaweisms.api.user
import huaweisms.api.sms
import urllib

ctx = huaweisms.api.user.quick_login("admin", "admin", modem_host='192.168.3.1')
phone = "+79261234567"
message = "Тест"
result = huaweisms.api.sms.send_sms(ctx, phone, message)
print(result)

Output

Traceback (most recent call last):
  File "/root/./test.py", line 10, in <module>
    result = huaweisms.api.sms.send_sms(ctx, phone, message)
  File "/usr/local/lib/python3.9/dist-packages/huaweisms/api/sms.py", line 77, in send_sms
    r = post_to_url(url, xml_data, ctx, headers)
  File "/usr/local/lib/python3.9/dist-packages/huaweisms/api/common.py", line 111, in post_to_url
    r = requests.post(url, data=data, headers=headers, cookies=cookies, timeout=timeout, verify=verify)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 119, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 394, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 234, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/lib/python3.9/http/client.py", line 1279, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.9/http/client.py", line 1324, in _send_request
    body = _encode(body, 'body')
  File "/usr/lib/python3.9/http/client.py", line 167, in _encode
    raise UnicodeEncodeError(
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 90-93: Body ('Тест') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

To correct this issue, I change the line 111 in the file /usr/local/lib/python3.9/dist-packages/huaweisms/api/common.py.
It was:

    r = requests.post(url, data=data, headers=headers, cookies=cookies, timeout=timeout, verify=verify)

I correct:

    r = requests.post(url, data=data.encode(), headers=headers, cookies=cookies, timeout=timeout, verify=verify)

Works with huawei h122-373

Just thought you may want to know that I have done a little testing with Huawei h122-373 (HUAWEI 5G CPE Pro 2 locked to UK Network Three). Nothing extensive, but can confirm your program successfully logs in, can list devices and sms messages

Getting battery status

Hello,

Thank you for your work on this.

I want to add support for getting the battery status. Any pointers on where I should start?

Thank you.

EDIT 1:
I was able to get some information out using the get_from_url () function. I will keep this thread updated.

url = "{}/monitoring/status".format(ctx.api_base_url)
huaweisms.api.common.get_from_url(url, ctx)

reboot does not seem to work

Hello! I have been testing the code from this repository on a Huawei E8372-155 router.

The thing that I have been trying to do is reboot this modem, remotely, by using your API, when the modem loses it's connection.

The problem is that the reboot does not seems to actually reboot the modem, it's lights are always in the same state and the connection stays always "Disconnected". I have to cut the power from the router so it really reboots.

Also when I use the command

huaweisms.api.dialup.switch_mobile_on(ctx)

and then check its current state with the command

huaweisms.api.dialup.get_mobile_status(ctx)

I receive the message "CONNECTED", even thou in the "site" of the router, the status appears always as "Disconnected" (like in the image below).

Capture

Error while working with USSD Code

Hello,

Firstly, congrats you created awesome library.
FYI: Connection to wingle, sending sms and reboot functions work great but USSD code doesn't work. No matter what I changed in the code so May I ask you?

Lately I found an Error while working with USSD code:
Heres the code:

import huaweisms.api.user
import huaweisms.api.wlan
import huaweisms.api.sms
import huaweisms.api.ussd
import huaweisms.api.device

ctx = huaweisms.api.user.quick_login("admin", "admin123")
print(ctx)
#Till this line it works Great



#This ussd code is to check balance: *101#
#This code doesn't work, no matter what I changed:
r = huaweisms.api.ussd.send(ctx, "*101#")
print(r)

print("\n........................\n")

r = huaweisms.api.ussd.get(ctx)
print(r)


#connected devices
device_list = huaweisms.api.wlan.get_connected_hosts(ctx)

When I execute this code it gives following error:

c:\python_codes>py ussd.py
<ApiCtx modem_host=192.168.8.1>
{'type': 'error', 'error': {'code': '1001', 'message': ''}}

........................

{'type': 'error', 'error': {'code': '100002', 'message': ''}}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.