This example shows how the 51Degrees device detection engine deals with
evidence that does not match any known device.
In this scenario, 'HasValue' can be used to check if the property has been
populated by the engine. If it hasn't then 'NoValueMessage' can be used
to get the reason why.
To run this example, you will need to create a resource key.
The resource key is used as shorthand to store the particular set of
properties you are interested in as well as any associated license keys
that entitle you to increased request limits and/or paid-for properties.
You can create a resource key using the 51Degrees Configurator.
Expected output:
1 Is user agent
'--' a mobile?
2 The results contained a null profile
for the component which the required property belongs to.
4 Is user agent
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114' a mobile?
39 from fiftyone_devicedetection.devicedetection_pipelinebuilder
import DeviceDetectionPipelineBuilder
46 resourceKey =
"!!YOUR_RESOURCE_KEY!!" 48 if resourceKey ==
"!!YOUR_RESOURCE_KEY!!":
50 You need to create a resource key at 51 https://configure.51degrees.com and paste it into the code, 52 'replacing !!YOUR_RESOURCE_KEY!! 53 To include the properties used in this example, go to https://configure.51degrees.com/bxXqZhLT 57 pipeline = DeviceDetectionPipelineBuilder({
"resourceKey": resourceKey}).build()
62 flowData1 = pipeline.create_flowdata()
66 iphoneUA =
"Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114" 68 flowData1.evidence.add(
"header.user-agent", iphoneUA)
79 print(
"Is User-Agent " + iphoneUA +
" a mobile device?: ")
80 if flowData1.device.ismobile.has_value():
81 print(flowData1.device.ismobile.value())
84 print(flowData1.device.ismobile.no_value_message())
90 flowData2 = pipeline.create_flowdata()
92 flowData2.evidence.add(
"header.user-agent", badUA)
96 print(
"Is User-Agent " + badUA +
" a mobile device?: ")
97 if flowData2.device.ismobile.has_value():
98 print(flowData2.device.ismobile.value())
101 print(flowData2.device.ismobile.no_value_message())