Install & Compatibility
Where this runs
tested against v0.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.018s · 69.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.2s · import 0.016s · 22MB
44MB installed
● package 44MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
requests (and stdlib hmac/hashlib)
✓ import hmac, hashlib, base64, json, uuid
import requests
✗ from linepay import LinePayApi
No official SDK. Use raw requests with manual HMAC-SHA256 signing. Community SDKs (line-pay, linepay) are both unmaintained.
Auth requires manual HMAC-SHA256 signing — secret is both the key and the first message segment. Use sandbox URL for testing; swap to production via env var before going live.
import hmac, hashlib, base64, json, uuid
import requests
CHANNEL_ID = 'your_channel_id'
CHANNEL_SECRET = 'your_channel_secret'
BASE_URL = 'https://sandbox-api-pay.line.me' # prod: https://api-pay.line.me
def sign(secret, uri, body_str, nonce):
# KEY GOTCHA: secret is used as BOTH the HMAC key AND prepended to the message
msg = secret + uri + body_str + nonce
return base64.b64encode(
hmac.new(secret.encode(), msg.encode(), hashlib.sha256).digest()
).decode()
def request_payment(amount, currency, order_id, confirm_url, cancel_url):
uri = '/v3/payments/request'
nonce = str(uuid.uuid4())
body = {
'amount': amount,
'currency': currency,
'orderId': order_id,
'packages': [{
'id': 'pkg1',
'amount': amount,
'products': [{'name': 'Product', 'quantity': 1, 'price': amount}]
}],
'redirectUrls': {
'confirmUrl': confirm_url,
'cancelUrl': cancel_url
}
}
body_str = json.dumps(body, separators=(',', ':')) # compact JSON, no spaces
signature = sign(CHANNEL_SECRET, uri, body_str, nonce)
headers = {
'Content-Type': 'application/json',
'X-LINE-ChannelId': CHANNEL_ID,
'X-LINE-Authorization-Nonce': nonce,
'X-LINE-Authorization': signature
}
resp = requests.post(BASE_URL + uri, headers=headers, data=body_str)
return resp.json()
result = request_payment(250, 'TWD', 'order-001',
'https://yoursite.com/confirm', 'https://yoursite.com/cancel')
print(result['info']['paymentUrl']['web']) # redirect user here
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'line_pay'
The 'line-pay' package is not installed in your current Python environment.
fixRun `pip install line-pay` in your terminal to install the library.
ImportError: cannot import name 'LinePayApi' from 'line_pay'
The class or object 'LinePayApi' cannot be found directly under the 'line_pay' module, possibly due to a typo, an outdated import path, or a change in the library's structure.
fixVerify the correct class name and import path by consulting the library's source code or available documentation, or try alternative imports like `from line_pay.api import LinePayApi`.
AttributeError: 'LinePayApi' object has no attribute 'request'
You are attempting to call a method or access an attribute named 'request' that does not exist on the `LinePayApi` object, likely due to a typo, an outdated method name, or an incomplete/changed API in the unmaintained library.
fixInspect the `LinePayApi` object's available attributes and methods using `dir(your_linepay_object)` or review the library's source code to find the correct method names for your desired operation.
LINE Pay 1106 error
Error code 1106 from the LINE Pay API indicates an 'Header information error', most commonly when the X-LINE-Authorization (MAC/signature) is incorrect or malformed due to issues with the Channel Secret, request body formatting, or nonce generation.
fixCarefully re-check your LINE Pay Channel Secret, ensure the request body for signature generation is exactly as expected (e.g., no extra whitespace, correct JSON key order), and verify that the HMAC-SHA256 signature calculation logic, including the nonce and UTF-8 encoding, is correct.
requests.exceptions.ConnectionError
The underlying 'requests' library, used by 'line-pay', failed to establish a network connection to the LINE Pay API server, possibly due to network issues, DNS problems, firewall restrictions, or an incorrect API endpoint.
fixCheck your network connectivity, confirm the LINE Pay API endpoint URL is correct, ensure no firewalls are blocking outgoing connections, and try to isolate if the issue is with network access or the API server itself.
Upgrade
Version history
0.2.0latest on PyPI · released Oct 7, 2020
Audit
Dependencies
requestsrequiredHTTP client for raw API calls